jdwpTransport.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  3. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. *
  5. *
  6. *
  7. *
  8. *
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *
  15. *
  16. *
  17. *
  18. *
  19. *
  20. *
  21. *
  22. *
  23. *
  24. */
  25. /*
  26. * Java Debug Wire Protocol Transport Service Provider Interface.
  27. */
  28. #ifndef JDWPTRANSPORT_H
  29. #define JDWPTRANSPORT_H
  30. #include "jni.h"
  31. enum {
  32. JDWPTRANSPORT_VERSION_1_0 = 0x00010000
  33. };
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. struct jdwpTransportNativeInterface_;
  38. struct _jdwpTransportEnv;
  39. #ifdef __cplusplus
  40. typedef _jdwpTransportEnv jdwpTransportEnv;
  41. #else
  42. typedef const struct jdwpTransportNativeInterface_ *jdwpTransportEnv;
  43. #endif /* __cplusplus */
  44. /*
  45. * Errors. Universal errors with JVMTI/JVMDI equivalents keep the
  46. * values the same.
  47. */
  48. typedef enum {
  49. JDWPTRANSPORT_ERROR_NONE = 0,
  50. JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT = 103,
  51. JDWPTRANSPORT_ERROR_OUT_OF_MEMORY = 110,
  52. JDWPTRANSPORT_ERROR_INTERNAL = 113,
  53. JDWPTRANSPORT_ERROR_ILLEGAL_STATE = 201,
  54. JDWPTRANSPORT_ERROR_IO_ERROR = 202,
  55. JDWPTRANSPORT_ERROR_TIMEOUT = 203,
  56. JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE = 204
  57. } jdwpTransportError;
  58. /*
  59. * Structure to define capabilities
  60. */
  61. typedef struct {
  62. unsigned int can_timeout_attach :1;
  63. unsigned int can_timeout_accept :1;
  64. unsigned int can_timeout_handshake :1;
  65. unsigned int reserved3 :1;
  66. unsigned int reserved4 :1;
  67. unsigned int reserved5 :1;
  68. unsigned int reserved6 :1;
  69. unsigned int reserved7 :1;
  70. unsigned int reserved8 :1;
  71. unsigned int reserved9 :1;
  72. unsigned int reserved10 :1;
  73. unsigned int reserved11 :1;
  74. unsigned int reserved12 :1;
  75. unsigned int reserved13 :1;
  76. unsigned int reserved14 :1;
  77. unsigned int reserved15 :1;
  78. } JDWPTransportCapabilities;
  79. /*
  80. * Structures to define packet layout.
  81. *
  82. * See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html
  83. */
  84. enum {
  85. /*
  86. * If additional flags are added that apply to jdwpCmdPacket,
  87. * then debugLoop.c: reader() will need to be updated to
  88. * accept more than JDWPTRANSPORT_FLAGS_NONE.
  89. */
  90. JDWPTRANSPORT_FLAGS_NONE = 0x0,
  91. JDWPTRANSPORT_FLAGS_REPLY = 0x80
  92. };
  93. typedef struct {
  94. jint len;
  95. jint id;
  96. jbyte flags;
  97. jbyte cmdSet;
  98. jbyte cmd;
  99. jbyte *data;
  100. } jdwpCmdPacket;
  101. typedef struct {
  102. jint len;
  103. jint id;
  104. jbyte flags;
  105. jshort errorCode;
  106. jbyte *data;
  107. } jdwpReplyPacket;
  108. typedef struct {
  109. union {
  110. jdwpCmdPacket cmd;
  111. jdwpReplyPacket reply;
  112. } type;
  113. } jdwpPacket;
  114. /*
  115. * JDWP functions called by the transport.
  116. */
  117. typedef struct jdwpTransportCallback {
  118. void *(*alloc)(jint numBytes); /* Call this for all allocations */
  119. void (*free)(void *buffer); /* Call this for all deallocations */
  120. } jdwpTransportCallback;
  121. typedef jint (JNICALL *jdwpTransport_OnLoad_t)(JavaVM *jvm,
  122. jdwpTransportCallback *callback,
  123. jint version,
  124. jdwpTransportEnv** env);
  125. /* Function Interface */
  126. struct jdwpTransportNativeInterface_ {
  127. /* 1 : RESERVED */
  128. void *reserved1;
  129. /* 2 : Get Capabilities */
  130. jdwpTransportError (JNICALL *GetCapabilities)(jdwpTransportEnv* env,
  131. JDWPTransportCapabilities *capabilities_ptr);
  132. /* 3 : Attach */
  133. jdwpTransportError (JNICALL *Attach)(jdwpTransportEnv* env,
  134. const char* address,
  135. jlong attach_timeout,
  136. jlong handshake_timeout);
  137. /* 4: StartListening */
  138. jdwpTransportError (JNICALL *StartListening)(jdwpTransportEnv* env,
  139. const char* address,
  140. char** actual_address);
  141. /* 5: StopListening */
  142. jdwpTransportError (JNICALL *StopListening)(jdwpTransportEnv* env);
  143. /* 6: Accept */
  144. jdwpTransportError (JNICALL *Accept)(jdwpTransportEnv* env,
  145. jlong accept_timeout,
  146. jlong handshake_timeout);
  147. /* 7: IsOpen */
  148. jboolean (JNICALL *IsOpen)(jdwpTransportEnv* env);
  149. /* 8: Close */
  150. jdwpTransportError (JNICALL *Close)(jdwpTransportEnv* env);
  151. /* 9: ReadPacket */
  152. jdwpTransportError (JNICALL *ReadPacket)(jdwpTransportEnv* env,
  153. jdwpPacket *pkt);
  154. /* 10: Write Packet */
  155. jdwpTransportError (JNICALL *WritePacket)(jdwpTransportEnv* env,
  156. const jdwpPacket* pkt);
  157. /* 11: GetLastError */
  158. jdwpTransportError (JNICALL *GetLastError)(jdwpTransportEnv* env,
  159. char** error);
  160. };
  161. /*
  162. * Use inlined functions so that C++ code can use syntax such as
  163. * env->Attach("mymachine:5000", 10*1000, 0);
  164. *
  165. * rather than using C's :-
  166. *
  167. * (*env)->Attach(env, "mymachine:5000", 10*1000, 0);
  168. */
  169. struct _jdwpTransportEnv {
  170. const struct jdwpTransportNativeInterface_ *functions;
  171. #ifdef __cplusplus
  172. jdwpTransportError GetCapabilities(JDWPTransportCapabilities *capabilities_ptr) {
  173. return functions->GetCapabilities(this, capabilities_ptr);
  174. }
  175. jdwpTransportError Attach(const char* address, jlong attach_timeout,
  176. jlong handshake_timeout) {
  177. return functions->Attach(this, address, attach_timeout, handshake_timeout);
  178. }
  179. jdwpTransportError StartListening(const char* address,
  180. char** actual_address) {
  181. return functions->StartListening(this, address, actual_address);
  182. }
  183. jdwpTransportError StopListening(void) {
  184. return functions->StopListening(this);
  185. }
  186. jdwpTransportError Accept(jlong accept_timeout, jlong handshake_timeout) {
  187. return functions->Accept(this, accept_timeout, handshake_timeout);
  188. }
  189. jboolean IsOpen(void) {
  190. return functions->IsOpen(this);
  191. }
  192. jdwpTransportError Close(void) {
  193. return functions->Close(this);
  194. }
  195. jdwpTransportError ReadPacket(jdwpPacket *pkt) {
  196. return functions->ReadPacket(this, pkt);
  197. }
  198. jdwpTransportError WritePacket(const jdwpPacket* pkt) {
  199. return functions->WritePacket(this, pkt);
  200. }
  201. jdwpTransportError GetLastError(char** error) {
  202. return functions->GetLastError(this, error);
  203. }
  204. #endif /* __cplusplus */
  205. };
  206. #ifdef __cplusplus
  207. } /* extern "C" */
  208. #endif /* __cplusplus */
  209. #endif /* JDWPTRANSPORT_H */