Skip to content

Add version fields for debugger configuration #2166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jerry-core/debugger/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions jerry-core/debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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. */
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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;

/**
Expand Down
14 changes: 13 additions & 1 deletion jerry-debugger/jerry-client-ws.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
<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;
Expand Down Expand Up @@ -136,6 +139,7 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
var outputResult = null;
var exceptionData = null;
var display = 0;
var version = 0;

function assert(expr)
{
Expand Down Expand Up @@ -783,7 +787,7 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
if (cpointerSize == 0)
{
if (message[0] != JERRY_DEBUGGER_CONFIGURATION
|| message.byteLength != 4)
|| message.byteLength != 5)
{
abortConnection("the first message must be configuration.");
}
Expand All @@ -792,11 +796,19 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
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;
}
Expand Down
14 changes: 12 additions & 2 deletions jerry-debugger/jerry-client-ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
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
Expand Down Expand Up @@ -563,13 +566,14 @@ def __init__(self, address):
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)
Expand All @@ -578,7 +582,7 @@ def __init__(self, address):

expected = struct.pack("BBB",
WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT,
4,
5,
JERRY_DEBUGGER_CONFIGURATION)

if result[0:3] != expected:
Expand All @@ -587,6 +591,12 @@ def __init__(self, address):
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 = "<"
Expand Down