gdbstub.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /// Stop gdbstub server.
  37. void Shutdown();
  38. /// Checks if the gdbstub server is enabled.
  39. bool IsServerEnabled();
  40. /// Returns true if there is an active socket connection.
  41. bool IsConnected();
  42. /// Register module.
  43. void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext = true);
  44. /**
  45. * Signal to the gdbstub server that it should halt CPU execution.
  46. *
  47. * @param is_memory_break If true, the break resulted from a memory breakpoint.
  48. */
  49. void Break(bool is_memory_break = false);
  50. /// Determine if there was a memory breakpoint.
  51. bool IsMemoryBreak();
  52. /// Read and handle packet from gdb client.
  53. void HandlePacket();
  54. /**
  55. * Get the nearest breakpoint of the specified type at the given address.
  56. *
  57. * @param addr Address to search from.
  58. * @param type Type of breakpoint.
  59. */
  60. BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, GDBStub::BreakpointType type);
  61. /**
  62. * Check if a breakpoint of the specified type exists at the given address.
  63. *
  64. * @param addr Address of breakpoint.
  65. * @param type Type of breakpoint.
  66. */
  67. bool CheckBreakpoint(VAddr addr, GDBStub::BreakpointType type);
  68. /// If set to true, the CPU will halt at the beginning of the next CPU loop.
  69. bool GetCpuHaltFlag();
  70. /// If set to true and the CPU is halted, the CPU will step one instruction.
  71. bool GetCpuStepFlag();
  72. /**
  73. * When set to true, the CPU will step one instruction when the CPU is halted next.
  74. *
  75. * @param is_step
  76. */
  77. void SetCpuStepFlag(bool is_step);
  78. /**
  79. * Send trap signal from thread back to the gdbstub server.
  80. *
  81. * @param thread Sending thread.
  82. * @param trap Trap no.
  83. */
  84. void SendTrap(Kernel::Thread* thread, int trap);
  85. } // namespace GDBStub