gdbserver.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2021 Ant Group. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _GDB_SERVER_H
  6. #define _GDB_SERVER_H
  7. #include "bh_platform.h"
  8. #define PACKET_BUF_SIZE 0x8000
  9. enum GDBStoppointType {
  10. eStoppointInvalid = -1,
  11. eBreakpointSoftware = 0,
  12. eBreakpointHardware,
  13. eWatchpointWrite,
  14. eWatchpointRead,
  15. eWatchpointReadWrite
  16. };
  17. typedef enum rsp_recv_phase_t {
  18. Phase_Idle,
  19. Phase_Payload,
  20. Phase_Checksum
  21. } rsp_recv_phase_t;
  22. /* Remote Serial Protocol Receive Context */
  23. typedef struct rsp_recv_context_t {
  24. rsp_recv_phase_t phase;
  25. uint16 receive_index;
  26. uint16 size_in_phase;
  27. uint8 check_sum;
  28. /* RSP packet should not be too long */
  29. char receive_buffer[1024];
  30. } rsp_recv_context_t;
  31. typedef struct WasmDebugPacket {
  32. unsigned char buf[PACKET_BUF_SIZE];
  33. uint32 size;
  34. } WasmDebugPacket;
  35. struct WASMDebugControlThread;
  36. typedef struct WASMGDBServer {
  37. bh_socket_t listen_fd;
  38. bh_socket_t socket_fd;
  39. WasmDebugPacket pkt;
  40. bool noack;
  41. struct WASMDebugControlThread *thread;
  42. rsp_recv_context_t *receive_ctx;
  43. } WASMGDBServer;
  44. WASMGDBServer *
  45. wasm_create_gdbserver(const char *host, int *port);
  46. bool
  47. wasm_gdbserver_listen(WASMGDBServer *server);
  48. bool
  49. wasm_gdbserver_accept(WASMGDBServer *server);
  50. void
  51. wasm_gdbserver_detach(WASMGDBServer *server);
  52. void
  53. wasm_close_gdbserver(WASMGDBServer *server);
  54. bool
  55. wasm_gdbserver_handle_packet(WASMGDBServer *server);
  56. #endif