debug_engine.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (C) 2021 Ant Group. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _DEBUG_ENGINE_H
  6. #define _DEBUG_ENGINE_H
  7. #include "bh_list.h"
  8. #include "gdbserver.h"
  9. #include "thread_manager.h"
  10. typedef enum WASMDebugControlThreadStatus {
  11. RUNNING,
  12. STOPPED,
  13. } WASMDebugControlThreadStatus;
  14. struct WASMDebugObject;
  15. typedef struct WASMDebugControlThread {
  16. WASMGDBServer *server;
  17. korp_tid tid;
  18. korp_mutex wait_lock;
  19. korp_cond wait_cond;
  20. char ip_addr[128];
  21. int port;
  22. WASMDebugControlThreadStatus status;
  23. struct WASMDebugObject *debug_engine;
  24. struct WASMDebugObject *debug_instance;
  25. } WASMDebugControlThread;
  26. typedef struct WASMDebugObject {
  27. struct WASMDebugObject *next;
  28. WASMDebugControlThread *control_thread;
  29. } WASMDebugObject;
  30. typedef struct WASMDebugBreakPoint {
  31. struct WASMDebugBreakPoint *next;
  32. uint64 addr;
  33. uint64 orignal_data;
  34. } WASMDebugBreakPoint;
  35. typedef struct WASMDebugInstance {
  36. struct WASMDebugInstance *next;
  37. WASMDebugControlThread *control_thread;
  38. bh_list break_point_list;
  39. WASMCluster *cluster;
  40. uint32 id;
  41. korp_tid current_tid;
  42. } WASMDebugInstance;
  43. typedef enum WASMDebugEventKind {
  44. BREAK_POINT_ADD,
  45. BREAK_POINT_REMOVE
  46. } WASMDebugEventKind;
  47. typedef struct WASMDebugEvent {
  48. WASMDebugEventKind kind;
  49. unsigned char metadata[0];
  50. } WASMDebugEvent;
  51. typedef struct WASMDebugMemoryInfo {
  52. uint64 start;
  53. uint64 size;
  54. char name[128];
  55. char permisson[4];
  56. } WASMDebugMemoryInfo;
  57. typedef enum WasmAddressType {
  58. WasmMemory = 0x00,
  59. WasmObj = 0x01,
  60. WasmInvalid = 0x03
  61. } WasmAddressType;
  62. #define WASM_ADDR(type, id, offset) \
  63. (((uint64)type << 62) | ((uint64)0 << 32) | ((uint64)offset << 0))
  64. #define WASM_ADDR_TYPE(addr) (((addr)&0xC000000000000000) >> 62)
  65. #define WASM_ADDR_OFFSET(addr) (((addr)&0x00000000FFFFFFFF))
  66. #define INVALIED_ADDR (0xFFFFFFFFFFFFFFFF)
  67. WASMDebugInstance *
  68. wasm_debug_instance_create(WASMCluster *cluster);
  69. void
  70. wasm_debug_instance_destroy(WASMCluster *cluster);
  71. WASMDebugInstance *
  72. wasm_exec_env_get_instance(WASMExecEnv *exec_env);
  73. bool
  74. wasm_debug_engine_init(char *ip_addr, int platform_port, int process_port);
  75. void
  76. wasm_debug_engine_destroy();
  77. void
  78. wasm_debug_set_engine_active(bool active);
  79. bool
  80. wasm_debug_get_engine_active(void);
  81. uint64
  82. wasm_debug_instance_get_pid(WASMDebugInstance *instance);
  83. uint64
  84. wasm_debug_instance_get_tid(WASMDebugInstance *instance);
  85. int
  86. wasm_debug_instance_get_tids(WASMDebugInstance *instance,
  87. uint64 tids[], int len);
  88. void
  89. wasm_debug_instance_set_cur_thread(WASMDebugInstance *instance, uint64 tid);
  90. uint64
  91. wasm_debug_instance_get_pc(WASMDebugInstance *instance);
  92. uint64
  93. wasm_debug_instance_get_load_addr(WASMDebugInstance *instance);
  94. WASMDebugMemoryInfo *
  95. wasm_debug_instance_get_memregion(WASMDebugInstance *instance, uint64 addr);
  96. void
  97. wasm_debug_instance_destroy_memregion(WASMDebugInstance *instance,
  98. WASMDebugMemoryInfo *mem_info);
  99. bool
  100. wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
  101. uint64 addr, char *buf, uint64 *size);
  102. bool
  103. wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
  104. uint64 addr, char *buf, uint64 *size);
  105. bool
  106. wasm_debug_instance_get_mem(WASMDebugInstance *instance,
  107. uint64 addr, char *buf, uint64 *size);
  108. bool
  109. wasm_debug_instance_set_mem(WASMDebugInstance *instance,
  110. uint64 addr, char *buf, uint64 *size);
  111. int
  112. wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
  113. uint64 tid, uint64 buf[], uint64 size);
  114. bool
  115. wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
  116. uint64 addr, uint64 length);
  117. bool
  118. wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
  119. uint64 addr, uint64 length);
  120. bool
  121. wasm_debug_instance_continue(WASMDebugInstance *instance);
  122. bool
  123. wasm_debug_instance_kill(WASMDebugInstance *instance);
  124. uint64
  125. wasm_debug_instance_wait_thread(WASMDebugInstance *instance,
  126. uint64 tid, uint32 *status);
  127. bool
  128. wasm_debug_instance_singlestep(WASMDebugInstance *instance, uint64 tid);
  129. bool
  130. wasm_debug_instance_get_local(WASMDebugInstance *instance,
  131. int frame_index, int local_index,
  132. char buf[], int *size);
  133. bool
  134. wasm_debug_instance_get_global(WASMDebugInstance *instance,
  135. int frame_index, int global_index,
  136. char buf[], int *size);
  137. #if WASM_ENABLE_LIBC_WASI != 0
  138. bool
  139. wasm_debug_instance_get_current_object_name(WASMDebugInstance *instance,
  140. char name_buffer[], int len);
  141. #endif
  142. uint64
  143. wasm_debug_instance_mmap(WASMDebugInstance *instance,
  144. uint32 size, int map_port);
  145. bool
  146. wasm_debug_instance_ummap(WASMDebugInstance *instance, uint64 addr);
  147. #endif