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 pgal.u-szeged@partner.samsung.com
This commit is contained in:
Peter Gal 2018-01-15 18:10:37 +01:00 committed by yichoi
parent 52a14fa08f
commit 40d05cdca2
4 changed files with 45 additions and 3 deletions

View File

@ -30,6 +30,15 @@
#include <unistd.h>
#endif /* HAVE_TIME_H */
/**
* The number of message types in the debugger should reflect the
* debugger versioning.
*/
JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 26
&& JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT == 16
&& JERRY_DEBUGGER_VERSION == 1,
debugger_version_correlates_to_message_type_count);
/**
* Type cast the debugger send buffer into a specific type.
*/
@ -707,6 +716,7 @@ jerry_debugger_send_configuration (uint8_t max_message_size) /**< maximum messag
configuration_p->max_message_size = max_message_size;
configuration_p->cpointer_size = sizeof (jmem_cpointer_t);
configuration_p->little_endian = (endian_data.uint8_value[0] == 1);
configuration_p->version = JERRY_DEBUGGER_VERSION;
return jerry_debugger_send (sizeof (jerry_debugger_send_configuration_t));
} /* jerry_debugger_send_configuration */

View File

@ -23,6 +23,11 @@
/* JerryScript debugger protocol is a simplified version of RFC-6455 (WebSockets). */
/**
* JerryScript debugger protocol version.
*/
#define JERRY_DEBUGGER_VERSION (1)
/**
* Frequency of calling jerry_debugger_receive() by the VM.
*/
@ -125,6 +130,8 @@ typedef enum
JERRY_DEBUGGER_OUTPUT_RESULT = 24, /**< output sent by the program to the debugger */
JERRY_DEBUGGER_OUTPUT_RESULT_END = 25, /**< last output result data */
JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT, /**< number of different type of output messages by the debugger */
/* Messages sent by the client to server. */
/* The following messages are accepted in both run and breakpoint modes. */
@ -147,6 +154,8 @@ typedef enum
JERRY_DEBUGGER_GET_BACKTRACE = 13, /**< get backtrace */
JERRY_DEBUGGER_EVAL = 14, /**< first message of evaluating a string */
JERRY_DEBUGGER_EVAL_PART = 15, /**< next message of evaluating a string */
JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT, /**< number of different type of input messages */
} jerry_debugger_header_type_t;
/**
@ -189,6 +198,7 @@ typedef struct
uint8_t max_message_size; /**< maximum incoming message size */
uint8_t cpointer_size; /**< size of compressed pointers */
uint8_t little_endian; /**< little endian machine */
uint8_t version; /**< debugger version */
} jerry_debugger_send_configuration_t;
/**

View File

@ -35,6 +35,9 @@ textarea {
<div>
</div>
<script>
// Expected JerryScript debugger protocol version
var JERRY_DEBUGGER_VERSION = 1;
// Messages sent by the server to client.
var JERRY_DEBUGGER_CONFIGURATION = 1;
var JERRY_DEBUGGER_PARSE_ERROR = 2;
@ -136,6 +139,7 @@ function DebuggerClient(address)
var outputResult = null;
var exceptionData = null;
var display = 0;
var version = 0;
function assert(expr)
{
@ -783,7 +787,7 @@ function DebuggerClient(address)
if (cpointerSize == 0)
{
if (message[0] != JERRY_DEBUGGER_CONFIGURATION
|| message.byteLength != 4)
|| message.byteLength != 5)
{
abortConnection("the first message must be configuration.");
}
@ -792,11 +796,19 @@ function DebuggerClient(address)
cpointerSize = message[2]
littleEndian = (message[3] != 0);
version = message[4];
if (cpointerSize != 2 && cpointerSize != 4)
{
abortConnection("compressed pointer must be 2 or 4 byte long.");
}
if (version != JERRY_DEBUGGER_VERSION)
{
abortConnection("incorrect target debugger version detected: "
+ version + " expected: " + JERRY_DEBUGGER_VERSION);
}
config = false;
return;
}

View File

@ -25,6 +25,9 @@ import socket
import struct
import sys
# Expected debugger protocol version.
JERRY_DEBUGGER_VERSION = 1
# Messages sent by the server to client.
JERRY_DEBUGGER_CONFIGURATION = 1
JERRY_DEBUGGER_PARSE_ERROR = 2
@ -563,13 +566,14 @@ class JerryDebugger(object):
else:
result = b""
len_expected = 6
len_expected = 7
# Network configurations, which has the following struct:
# header [2] - opcode[1], size[1]
# type [1]
# max_message_size [1]
# cpointer_size [1]
# little_endian [1]
# version [1]
while len(result) < len_expected:
result += self.client_socket.recv(1024)
@ -578,7 +582,7 @@ class JerryDebugger(object):
expected = struct.pack("BBB",
WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT,
4,
5,
JERRY_DEBUGGER_CONFIGURATION)
if result[0:3] != expected:
@ -587,6 +591,12 @@ class JerryDebugger(object):
self.max_message_size = ord(result[3])
self.cp_size = ord(result[4])
self.little_endian = ord(result[5])
self.version = ord(result[6])
if self.version != JERRY_DEBUGGER_VERSION:
raise Exception("Incorrect debugger version from target: %d expected: %d" %
(self.version, JERRY_DEBUGGER_VERSION))
if self.little_endian:
self.byte_order = "<"