Skip to content

Commit 40d05cd

Browse files
galpeteryichoi
authored andcommitted
Add version fields for debugger configuration
By adding version information to the debugger protocol it is possible to report if the debugger client and server have different expectations on debugger workings (opcodes, types, etc.). JerryScript-DCO-1.0-Signed-off-by: Peter Gal [email protected]
1 parent 52a14fa commit 40d05cd

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

jerry-core/debugger/debugger.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
#include <unistd.h>
3131
#endif /* HAVE_TIME_H */
3232

33+
/**
34+
* The number of message types in the debugger should reflect the
35+
* debugger versioning.
36+
*/
37+
JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 26
38+
&& JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT == 16
39+
&& JERRY_DEBUGGER_VERSION == 1,
40+
debugger_version_correlates_to_message_type_count);
41+
3342
/**
3443
* Type cast the debugger send buffer into a specific type.
3544
*/
@@ -707,6 +716,7 @@ jerry_debugger_send_configuration (uint8_t max_message_size) /**< maximum messag
707716
configuration_p->max_message_size = max_message_size;
708717
configuration_p->cpointer_size = sizeof (jmem_cpointer_t);
709718
configuration_p->little_endian = (endian_data.uint8_value[0] == 1);
719+
configuration_p->version = JERRY_DEBUGGER_VERSION;
710720

711721
return jerry_debugger_send (sizeof (jerry_debugger_send_configuration_t));
712722
} /* jerry_debugger_send_configuration */

jerry-core/debugger/debugger.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323

2424
/* JerryScript debugger protocol is a simplified version of RFC-6455 (WebSockets). */
2525

26+
/**
27+
* JerryScript debugger protocol version.
28+
*/
29+
#define JERRY_DEBUGGER_VERSION (1)
30+
2631
/**
2732
* Frequency of calling jerry_debugger_receive() by the VM.
2833
*/
@@ -125,6 +130,8 @@ typedef enum
125130
JERRY_DEBUGGER_OUTPUT_RESULT = 24, /**< output sent by the program to the debugger */
126131
JERRY_DEBUGGER_OUTPUT_RESULT_END = 25, /**< last output result data */
127132

133+
JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT, /**< number of different type of output messages by the debugger */
134+
128135
/* Messages sent by the client to server. */
129136

130137
/* The following messages are accepted in both run and breakpoint modes. */
@@ -147,6 +154,8 @@ typedef enum
147154
JERRY_DEBUGGER_GET_BACKTRACE = 13, /**< get backtrace */
148155
JERRY_DEBUGGER_EVAL = 14, /**< first message of evaluating a string */
149156
JERRY_DEBUGGER_EVAL_PART = 15, /**< next message of evaluating a string */
157+
158+
JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT, /**< number of different type of input messages */
150159
} jerry_debugger_header_type_t;
151160

152161
/**
@@ -189,6 +198,7 @@ typedef struct
189198
uint8_t max_message_size; /**< maximum incoming message size */
190199
uint8_t cpointer_size; /**< size of compressed pointers */
191200
uint8_t little_endian; /**< little endian machine */
201+
uint8_t version; /**< debugger version */
192202
} jerry_debugger_send_configuration_t;
193203

194204
/**

jerry-debugger/jerry-client-ws.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
3535
<div>
3636
</div>
3737
<script>
38+
// Expected JerryScript debugger protocol version
39+
var JERRY_DEBUGGER_VERSION = 1;
40+
3841
// Messages sent by the server to client.
3942
var JERRY_DEBUGGER_CONFIGURATION = 1;
4043
var JERRY_DEBUGGER_PARSE_ERROR = 2;
@@ -136,6 +139,7 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
136139
var outputResult = null;
137140
var exceptionData = null;
138141
var display = 0;
142+
var version = 0;
139143

140144
function assert(expr)
141145
{
@@ -783,7 +787,7 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
783787
if (cpointerSize == 0)
784788
{
785789
if (message[0] != JERRY_DEBUGGER_CONFIGURATION
786-
|| message.byteLength != 4)
790+
|| message.byteLength != 5)
787791
{
788792
abortConnection("the first message must be configuration.");
789793
}
@@ -792,11 +796,19 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
792796
cpointerSize = message[2]
793797
littleEndian = (message[3] != 0);
794798

799+
version = message[4];
800+
795801
if (cpointerSize != 2 && cpointerSize != 4)
796802
{
797803
abortConnection("compressed pointer must be 2 or 4 byte long.");
798804
}
799805

806+
if (version != JERRY_DEBUGGER_VERSION)
807+
{
808+
abortConnection("incorrect target debugger version detected: "
809+
+ version + " expected: " + JERRY_DEBUGGER_VERSION);
810+
}
811+
800812
config = false;
801813
return;
802814
}

jerry-debugger/jerry-client-ws.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import struct
2626
import sys
2727

28+
# Expected debugger protocol version.
29+
JERRY_DEBUGGER_VERSION = 1
30+
2831
# Messages sent by the server to client.
2932
JERRY_DEBUGGER_CONFIGURATION = 1
3033
JERRY_DEBUGGER_PARSE_ERROR = 2
@@ -563,13 +566,14 @@ def __init__(self, address):
563566
else:
564567
result = b""
565568

566-
len_expected = 6
569+
len_expected = 7
567570
# Network configurations, which has the following struct:
568571
# header [2] - opcode[1], size[1]
569572
# type [1]
570573
# max_message_size [1]
571574
# cpointer_size [1]
572575
# little_endian [1]
576+
# version [1]
573577

574578
while len(result) < len_expected:
575579
result += self.client_socket.recv(1024)
@@ -578,7 +582,7 @@ def __init__(self, address):
578582

579583
expected = struct.pack("BBB",
580584
WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT,
581-
4,
585+
5,
582586
JERRY_DEBUGGER_CONFIGURATION)
583587

584588
if result[0:3] != expected:
@@ -587,6 +591,12 @@ def __init__(self, address):
587591
self.max_message_size = ord(result[3])
588592
self.cp_size = ord(result[4])
589593
self.little_endian = ord(result[5])
594+
self.version = ord(result[6])
595+
596+
if self.version != JERRY_DEBUGGER_VERSION:
597+
raise Exception("Incorrect debugger version from target: %d expected: %d" %
598+
(self.version, JERRY_DEBUGGER_VERSION))
599+
590600

591601
if self.little_endian:
592602
self.byte_order = "<"

0 commit comments

Comments
 (0)