Home | History | Annotate | Download | only in export
      1 /*
      2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     23  * questions.
     24  */
     25 
     26 /*
     27  * Java Debug Wire Protocol Transport Service Provider Interface.
     28  */
     29 
     30 #ifndef JDWPTRANSPORT_H
     31 #define JDWPTRANSPORT_H
     32 
     33 #include "jni.h"
     34 
     35 enum {
     36     JDWPTRANSPORT_VERSION_1_0 = 0x00010000
     37 };
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif
     42 
     43 struct jdwpTransportNativeInterface_;
     44 
     45 struct _jdwpTransportEnv;
     46 
     47 #ifdef __cplusplus
     48 typedef _jdwpTransportEnv jdwpTransportEnv;
     49 #else
     50 typedef const struct jdwpTransportNativeInterface_ *jdwpTransportEnv;
     51 #endif /* __cplusplus */
     52 
     53 /*
     54  * Errors. Universal errors with JVMTI/JVMDI equivalents keep the
     55  * values the same.
     56  */
     57 typedef enum {
     58     JDWPTRANSPORT_ERROR_NONE = 0,
     59     JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT = 103,
     60     JDWPTRANSPORT_ERROR_OUT_OF_MEMORY = 110,
     61     JDWPTRANSPORT_ERROR_INTERNAL = 113,
     62     JDWPTRANSPORT_ERROR_ILLEGAL_STATE = 201,
     63     JDWPTRANSPORT_ERROR_IO_ERROR = 202,
     64     JDWPTRANSPORT_ERROR_TIMEOUT = 203,
     65     JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE = 204
     66 } jdwpTransportError;
     67 
     68 
     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 
     92 /*
     93  * Structures to define packet layout.
     94  *
     95  * See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html
     96  */
     97 
     98 enum {
     99     /*
    100      * If additional flags are added that apply to jdwpCmdPacket,
    101      * then debugLoop.c: reader() will need to be updated to
    102      * accept more than JDWPTRANSPORT_FLAGS_NONE.
    103      */
    104     JDWPTRANSPORT_FLAGS_NONE     = 0x0,
    105     JDWPTRANSPORT_FLAGS_REPLY    = 0x80
    106 };
    107 
    108 typedef struct {
    109     jint len;
    110     jint id;
    111     jbyte flags;
    112     jbyte cmdSet;
    113     jbyte cmd;
    114     jbyte *data;
    115 } jdwpCmdPacket;
    116 
    117 typedef struct {
    118     jint len;
    119     jint id;
    120     jbyte flags;
    121     jshort errorCode;
    122     jbyte *data;
    123 } jdwpReplyPacket;
    124 
    125 typedef struct {
    126     union {
    127         jdwpCmdPacket cmd;
    128         jdwpReplyPacket reply;
    129     } type;
    130 } jdwpPacket;
    131 
    132 /*
    133  * JDWP functions called by the transport.
    134  */
    135 typedef struct jdwpTransportCallback {
    136     void *(*alloc)(jint numBytes);   /* Call this for all allocations */
    137     void (*free)(void *buffer);      /* Call this for all deallocations */
    138 } jdwpTransportCallback;
    139 
    140 typedef jint (JNICALL *jdwpTransport_OnLoad_t)(JavaVM *jvm,
    141                                                jdwpTransportCallback *callback,
    142                                                jint version,
    143                                                jdwpTransportEnv** env);
    144 
    145 
    146 
    147 /* Function Interface */
    148 
    149 struct jdwpTransportNativeInterface_ {
    150     /*  1 :  RESERVED */
    151     void *reserved1;
    152 
    153     /*  2 : Get Capabilities */
    154     jdwpTransportError (JNICALL *GetCapabilities)(jdwpTransportEnv* env,
    155          JDWPTransportCapabilities *capabilities_ptr);
    156 
    157     /*  3 : Attach */
    158     jdwpTransportError (JNICALL *Attach)(jdwpTransportEnv* env,
    159         const char* address,
    160         jlong attach_timeout,
    161         jlong handshake_timeout);
    162 
    163     /*  4: StartListening */
    164     jdwpTransportError (JNICALL *StartListening)(jdwpTransportEnv* env,
    165         const char* address,
    166         char** actual_address);
    167 
    168     /*  5: StopListening */
    169     jdwpTransportError (JNICALL *StopListening)(jdwpTransportEnv* env);
    170 
    171     /*  6: Accept */
    172     jdwpTransportError (JNICALL *Accept)(jdwpTransportEnv* env,
    173         jlong accept_timeout,
    174         jlong handshake_timeout);
    175 
    176     /*  7: IsOpen */
    177     jboolean (JNICALL *IsOpen)(jdwpTransportEnv* env);
    178 
    179     /*  8: Close */
    180     jdwpTransportError (JNICALL *Close)(jdwpTransportEnv* env);
    181 
    182     /*  9: ReadPacket */
    183     jdwpTransportError (JNICALL *ReadPacket)(jdwpTransportEnv* env,
    184         jdwpPacket *pkt);
    185 
    186     /*  10: Write Packet */
    187     jdwpTransportError (JNICALL *WritePacket)(jdwpTransportEnv* env,
    188         const jdwpPacket* pkt);
    189 
    190     /*  11:  GetLastError */
    191     jdwpTransportError (JNICALL *GetLastError)(jdwpTransportEnv* env,
    192         char** error);
    193 
    194 };
    195 
    196 
    197 /*
    198  * Use inlined functions so that C++ code can use syntax such as
    199  *      env->Attach("mymachine:5000", 10*1000, 0);
    200  *
    201  * rather than using C's :-
    202  *
    203  *      (*env)->Attach(env, "mymachine:5000", 10*1000, 0);
    204  */
    205 struct _jdwpTransportEnv {
    206     const struct jdwpTransportNativeInterface_ *functions;
    207 #ifdef __cplusplus
    208 
    209     jdwpTransportError GetCapabilities(JDWPTransportCapabilities *capabilities_ptr) {
    210         return functions->GetCapabilities(this, capabilities_ptr);
    211     }
    212 
    213     jdwpTransportError Attach(const char* address, jlong attach_timeout,
    214                 jlong handshake_timeout) {
    215         return functions->Attach(this, address, attach_timeout, handshake_timeout);
    216     }
    217 
    218     jdwpTransportError StartListening(const char* address,
    219                 char** actual_address) {
    220         return functions->StartListening(this, address, actual_address);
    221     }
    222 
    223     jdwpTransportError StopListening(void) {
    224         return functions->StopListening(this);
    225     }
    226 
    227     jdwpTransportError Accept(jlong accept_timeout, jlong handshake_timeout) {
    228         return functions->Accept(this, accept_timeout, handshake_timeout);
    229     }
    230 
    231     jboolean IsOpen(void) {
    232         return functions->IsOpen(this);
    233     }
    234 
    235     jdwpTransportError Close(void) {
    236         return functions->Close(this);
    237     }
    238 
    239     jdwpTransportError ReadPacket(jdwpPacket *pkt) {
    240         return functions->ReadPacket(this, pkt);
    241     }
    242 
    243     jdwpTransportError WritePacket(const jdwpPacket* pkt) {
    244         return functions->WritePacket(this, pkt);
    245     }
    246 
    247     jdwpTransportError GetLastError(char** error) {
    248         return functions->GetLastError(this, error);
    249     }
    250 
    251 
    252 #endif /* __cplusplus */
    253 };
    254 
    255 #ifdef __cplusplus
    256 } /* extern "C" */
    257 #endif /* __cplusplus */
    258 
    259 #endif /* JDWPTRANSPORT_H */
    260