Add bjdwp tool to Barry project.
[barry/progweb.git] / bjdwp / src / protocol.h
blobf87cb972d2e2961dda17636540ff2357b189a33e
1 #ifndef __BARRYJDWP_PROTOCOL_H__
2 #define __BARRYJDWP_PROTOCOL_H__
5 #include <stdint.h>
6 #include <sys/types.h>
9 // Command set list
10 #define JDWP_CMDSET_VIRTUALMACHINE 1
11 #define JDWP_CMDSET_REFERECENTYPE 2
12 #define JDWP_CMDSET_CLASSTYPE 3
13 #define JDWP_CMDSET_ARRAYTYPE 4
14 #define JDWP_CMDSET_INTERFACETYPE 5
15 #define JDWP_CMDSET_METHOD 6
16 #define JDWP_CMDSET_FIELD 8
17 #define JDWP_CMDSET_OBJECTREFERENCE 9
18 #define JDWP_CMDSET_STRINGREFERENCE 10
19 #define JDWP_CMDSET_THREADREFERENCE 11
20 #define JDWP_CMDSET_THREADGROUPREFERENCE 12
21 #define JDWP_CMDSET_ARRAYREFERENCE 13
22 #define JDWP_CMDSET_CLASSLOADERREFERENCE 14
23 #define JDWP_CMDSET_EVENTREQUEST 15
24 #define JDWP_CMDSET_STACKFRAME 16
25 #define JDWP_CMDSET_CLASSOBJECTREFERENCE 17
26 #define JDWP_CMDSET_EVENT 64
28 // Command list - VirtualMachine
29 #define JDWP_CMD_VERSION 1
30 #define JDWP_CMD_ALLCLASSES 3
31 #define JDWP_CMD_ALLTHREADS 4
32 #define JDWP_CMD_DISPOSE 6
33 #define JDWP_CMD_IDSIZES 7
34 #define JDWP_CMD_SUSPEND 8
35 #define JDWP_CMD_RESUME 9
36 #define JDWP_CMD_CLASSPATHS 13
38 // Command list - EventRequest
39 #define JDWP_CMD_SET 1
42 namespace JDWP { namespace Protocol {
44 // Packet command
45 //----------------
47 struct PacketEventRequestSet {
48 uint8_t eventKind;
49 uint8_t suspendPolicy;
50 uint32_t modifiers;
51 } __attribute__ ((packed));
54 struct PacketEventRequest {
55 union PacketEventRequestData {
56 PacketEventRequestSet set;
57 } __attribute__ ((packed)) u;
58 } __attribute__ ((packed));
61 struct PacketCommand {
62 uint8_t commandset;
63 uint8_t command;
65 union PacketCommandData {
66 PacketEventRequest eventRequest;
67 } __attribute__ ((packed)) u;
68 } __attribute__ ((packed));
70 #define JDWP_COMMAND_HEADER_SIZE (sizeof(Protocol::PacketCommand))
73 // Packet response
74 //-----------------
76 struct PacketVirtualMachineIDSizes {
77 uint32_t fieldIDSize;
78 uint32_t methodIDSize;
79 uint32_t objectIDSize;
80 uint32_t referenceTypeIDSize;
81 uint32_t frameIDSize;
82 } __attribute__ ((packed));
84 #define JDWP_PACKETVIRTUALMACHINEIDSIZES_DATA_SIZE sizeof(Protocol::PacketVirtualMachineIDSizes)
87 struct PacketVirtualMachine {
88 union PacketVirtualMachineData {
89 PacketVirtualMachineIDSizes IDSizes;
90 } __attribute__ ((packed)) u;
91 } __attribute__ ((packed));
94 struct PacketResponse {
95 uint16_t errorcode;
97 union PacketResponseData {
98 PacketVirtualMachine virtualMachine;
99 uint32_t value;
100 uint8_t raw[1];
101 } __attribute__ ((packed)) u;
102 } __attribute__ ((packed));
104 #define JDWP_RESPONSE_HEADER_SIZE (sizeof(Protocol::PacketResponse) - sizeof(Protocol::PacketResponse::PacketResponseData))
107 // Generic packet
108 //----------------
110 struct Packet {
111 uint32_t length;
112 uint32_t id;
113 uint8_t flags;
115 union PacketType {
116 PacketCommand command;
117 PacketResponse response;
118 } __attribute__ ((packed)) u;
119 } __attribute__ ((packed));
121 #define JDWP_PACKET_HEADER_SIZE (sizeof(Protocol::Packet) - sizeof(Protocol::Packet::PacketType))
124 #define MAKE_JDWPPACKET(var, data) const Protocol::Packet *var = (const Protocol::Packet *) (data).GetData()
125 #define MAKE_JDWPPACKETPTR_BUF(var, ptr) Protocol::Packet *var = (Protocol::Packet *)ptr
128 }} // namespace JDWP::Protocol
130 #endif