gdbstub.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2013 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. // Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
  5. #pragma once
  6. #include <atomic>
  7. #include "common/common_types.h"
  8. namespace GDBStub {
  9. /// Breakpoint Method
  10. enum class BreakpointType {
  11. None, ///< None
  12. Execute, ///< Execution Breakpoint
  13. Read, ///< Read Breakpoint
  14. Write, ///< Write Breakpoint
  15. Access ///< Access (R/W) Breakpoint
  16. };
  17. struct BreakpointAddress {
  18. PAddr address;
  19. BreakpointType type;
  20. };
  21. /// If set to false, the server will never be started and no gdbstub-related functions will be executed.
  22. extern std::atomic<bool> g_server_enabled;
  23. /**
  24. * Set the port the gdbstub should use to listen for connections.
  25. *
  26. * @param port Port to listen for connection
  27. */
  28. void SetServerPort(u16 port);
  29. /**
  30. * Set the g_server_enabled flag and start or stop the server if possible.
  31. *
  32. * @param status Set the server to enabled or disabled.
  33. */
  34. void ToggleServer(bool status);
  35. /// Start the gdbstub server.
  36. void Init();
  37. /// Stop gdbstub server.
  38. void Shutdown();
  39. /// Returns true if there is an active socket connection.
  40. bool IsConnected();
  41. /**
  42. * Signal to the gdbstub server that it should halt CPU execution.
  43. *
  44. * @param is_memory_break If true, the break resulted from a memory breakpoint.
  45. */
  46. void Break(bool is_memory_break = false);
  47. /// Determine if there was a memory breakpoint.
  48. bool IsMemoryBreak();
  49. /// Read and handle packet from gdb client.
  50. void HandlePacket();
  51. /**
  52. * Get the nearest breakpoint of the specified type at the given address.
  53. *
  54. * @param addr Address to search from.
  55. * @param type Type of breakpoint.
  56. */
  57. BreakpointAddress GetNextBreakpointFromAddress(u32 addr, GDBStub::BreakpointType type);
  58. /**
  59. * Check if a breakpoint of the specified type exists at the given address.
  60. *
  61. * @param addr Address of breakpoint.
  62. * @param type Type of breakpoint.
  63. */
  64. bool CheckBreakpoint(u32 addr, GDBStub::BreakpointType type);
  65. // If set to true, the CPU will halt at the beginning of the next CPU loop.
  66. bool GetCpuHaltFlag();
  67. // If set to true and the CPU is halted, the CPU will step one instruction.
  68. bool GetCpuStepFlag();
  69. /**
  70. * When set to true, the CPU will step one instruction when the CPU is halted next.
  71. *
  72. * @param is_step
  73. */
  74. void SetCpuStepFlag(bool is_step);
  75. }