gdbstub.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <string>
  7. #include "common/common_types.h"
  8. #include "core/hle/kernel/thread.h"
  9. namespace GDBStub {
  10. /// Breakpoint Method
  11. enum class BreakpointType {
  12. None, ///< None
  13. Execute, ///< Execution Breakpoint
  14. Read, ///< Read Breakpoint
  15. Write, ///< Write Breakpoint
  16. Access ///< Access (R/W) Breakpoint
  17. };
  18. struct BreakpointAddress {
  19. VAddr address;
  20. BreakpointType type;
  21. };
  22. /**
  23. * Set the port the gdbstub should use to listen for connections.
  24. *
  25. * @param port Port to listen for connection
  26. */
  27. void SetServerPort(u16 port);
  28. /**
  29. * Starts or stops the server if possible.
  30. *
  31. * @param status Set the server to enabled or disabled.
  32. */
  33. void ToggleServer(bool status);
  34. /// Start the gdbstub server.
  35. void Init();
  36. /**
  37. * Defer initialization of the gdbstub to the first packet processing functions.
  38. * This avoids a case where the gdbstub thread is frozen after initialization
  39. * and fails to respond in time to packets.
  40. */
  41. void DeferStart();
  42. /// Stop gdbstub server.
  43. void Shutdown();
  44. /// Checks if the gdbstub server is enabled.
  45. bool IsServerEnabled();
  46. /// Returns true if there is an active socket connection.
  47. bool IsConnected();
  48. /// Register module.
  49. void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext = true);
  50. /**
  51. * Signal to the gdbstub server that it should halt CPU execution.
  52. *
  53. * @param is_memory_break If true, the break resulted from a memory breakpoint.
  54. */
  55. void Break(bool is_memory_break = false);
  56. /// Determine if there was a memory breakpoint.
  57. bool IsMemoryBreak();
  58. /// Read and handle packet from gdb client.
  59. void HandlePacket();
  60. /**
  61. * Get the nearest breakpoint of the specified type at the given address.
  62. *
  63. * @param addr Address to search from.
  64. * @param type Type of breakpoint.
  65. */
  66. BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, GDBStub::BreakpointType type);
  67. /**
  68. * Check if a breakpoint of the specified type exists at the given address.
  69. *
  70. * @param addr Address of breakpoint.
  71. * @param type Type of breakpoint.
  72. */
  73. bool CheckBreakpoint(VAddr addr, GDBStub::BreakpointType type);
  74. /// If set to true, the CPU will halt at the beginning of the next CPU loop.
  75. bool GetCpuHaltFlag();
  76. /// If set to true and the CPU is halted, the CPU will step one instruction.
  77. bool GetCpuStepFlag();
  78. /**
  79. * When set to true, the CPU will step one instruction when the CPU is halted next.
  80. *
  81. * @param is_step
  82. */
  83. void SetCpuStepFlag(bool is_step);
  84. /**
  85. * Send trap signal from thread back to the gdbstub server.
  86. *
  87. * @param thread Sending thread.
  88. * @param trap Trap no.
  89. */
  90. void SendTrap(Kernel::Thread* thread, u32 trap);
  91. } // namespace GDBStub