gdbstub.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. namespace GDBStub {
  8. /// Breakpoint Method
  9. enum class BreakpointType {
  10. None, ///< None
  11. Execute, ///< Execution Breakpoint
  12. Read, ///< Read Breakpoint
  13. Write, ///< Write Breakpoint
  14. Access ///< Access (R/W) Breakpoint
  15. };
  16. /// If set to false, the server will never be started and no gdbstub-related functions will be executed.
  17. extern std::atomic<bool> g_server_enabled;
  18. /**
  19. * Set the port the gdbstub should use to listen for connections.
  20. *
  21. * @param port Port to listen for connection
  22. */
  23. void SetServerPort(u16 port);
  24. /**
  25. * Set the g_server_enabled flag and start or stop the server if possible.
  26. *
  27. * @param status Set the server to enabled or disabled.
  28. */
  29. void ToggleServer(bool status);
  30. /// Start the gdbstub server.
  31. void Init();
  32. /// Stop gdbstub server.
  33. void Deinit();
  34. /// Returns true if there is an active socket connection.
  35. bool IsConnected();
  36. /**
  37. * Signal to the gdbstub server that it should halt CPU execution.
  38. *
  39. * @param is_memory_break If true, the break resulted from a memory breakpoint.
  40. */
  41. void Break(bool is_memory_break = false);
  42. /// Determine if there was a memory breakpoint.
  43. bool IsMemoryBreak();
  44. /// Read and handle packet from gdb client.
  45. void HandlePacket();
  46. /**
  47. * Get the nearest breakpoint of the specified type at the given address.
  48. *
  49. * @param addr Address to search from.
  50. * @param type Type of breakpoint.
  51. */
  52. PAddr GetNextBreakpointFromAddress(u32 addr, GDBStub::BreakpointType type);
  53. /**
  54. * Check if a breakpoint of the specified type exists at the given address.
  55. *
  56. * @param addr Address of breakpoint.
  57. * @param type Type of breakpoint.
  58. */
  59. bool CheckBreakpoint(u32 addr, GDBStub::BreakpointType type);
  60. // If set to true, the CPU will halt at the beginning of the next CPU loop.
  61. bool GetCpuHaltFlag();
  62. // If set to true and the CPU is halted, the CPU will step one instruction.
  63. bool GetCpuStepFlag();
  64. /**
  65. * When set to true, the CPU will step one instruction when the CPU is halted next.
  66. *
  67. * @param is_step
  68. */
  69. void SetCpuStepFlag(bool is_step);
  70. }