jdwpTransport.h 6.5 KB

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