debug_engine.h 4.8 KB

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