Introduce debugger status flags to control the operation of the debugger. (#1596)

Two issues were fixed as well: inserting breakpoints before non-directive
prologue strings and the receive can process multiple messages.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2017-02-21 11:57:04 +01:00
committed by GitHub
parent 33138c09f5
commit 00e3de230f
9 changed files with 99 additions and 77 deletions
+21 -25
View File
@@ -65,9 +65,12 @@ typedef struct
static void
jerry_debugger_close_connection_tcp (bool log_error) /**< log error */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
JERRY_CONTEXT (jerry_init_flags) &= (uint32_t) ~JERRY_INIT_DEBUGGER;
uint8_t debugger_flags = JERRY_CONTEXT (debugger_flags);
debugger_flags = (uint8_t) (debugger_flags & ~(JERRY_DEBUGGER_CONNECTED | JERRY_DEBUGGER_VM_STOP));
debugger_flags = (uint8_t) (debugger_flags | JERRY_DEBUGGER_VM_IGNORE);
JERRY_CONTEXT (debugger_flags) = debugger_flags;
if (log_error)
{
@@ -92,7 +95,7 @@ static bool
jerry_debugger_send_tcp (const uint8_t *data_p, /**< data pointer */
size_t data_size) /**< data size */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
do
{
@@ -314,9 +317,6 @@ jerry_debugger_accept_connection ()
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
/* Disable debugger flag temporarily. */
JERRY_CONTEXT (jerry_init_flags) &= (uint32_t) ~JERRY_INIT_DEBUGGER;
addr.sin_family = AF_INET;
addr.sin_port = htons (JERRY_DEBUGGER_PORT);
addr.sin_addr.s_addr = INADDR_ANY;
@@ -363,8 +363,7 @@ jerry_debugger_accept_connection ()
close (server_socket);
/* Enable debugger flag again. */
JERRY_CONTEXT (jerry_init_flags) |= JERRY_INIT_DEBUGGER;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_CONNECTED);
bool is_handshake_ok = false;
@@ -403,7 +402,7 @@ jerry_debugger_accept_connection ()
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "Connected from: %s\n", inet_ntoa (addr.sin_addr));
JERRY_CONTEXT (debugger_stop_exec) = true;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
return true;
@@ -438,7 +437,7 @@ JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MAX_RECEIVE_SIZE < 126,
*
* Note:
* If the function returns with true, the value of
* JERRY_CONTEXT (debugger_stop_exec) should be ignored.
* JERRY_DEBUGGER_VM_STOP flag should be ignored.
*
* @return true - if execution should be resumed,
* false - otherwise
@@ -446,7 +445,7 @@ JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MAX_RECEIVE_SIZE < 126,
bool
jerry_debugger_receive (void)
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
JERRY_CONTEXT (debugger_message_delay) = JERRY_DEBUGGER_MESSAGE_FREQUENCY;
@@ -458,30 +457,27 @@ jerry_debugger_receive (void)
while (true)
{
uint32_t offset = JERRY_CONTEXT (debugger_receive_buffer_offset);
ssize_t byte_recv = recv (JERRY_CONTEXT (debugger_connection),
recv_buffer_p + offset,
JERRY_DEBUGGER_MAX_BUFFER_SIZE - offset,
0);
if (byte_recv <= 0)
if (byte_recv < 0)
{
if (byte_recv < 0 && errno != EWOULDBLOCK)
if (errno != EWOULDBLOCK)
{
jerry_debugger_close_connection_tcp (true);
return true;
}
if (expected_message_type != 0)
{
continue;
}
return resume_exec;
byte_recv = 0;
}
JERRY_CONTEXT (debugger_receive_buffer_offset) += (uint32_t) byte_recv;
offset += (uint32_t) byte_recv;
JERRY_CONTEXT (debugger_receive_buffer_offset) = (uint16_t) offset;
if (JERRY_CONTEXT (debugger_receive_buffer_offset) < sizeof (jerry_debugger_receive_header_t))
if (offset < sizeof (jerry_debugger_receive_header_t))
{
if (expected_message_type != 0)
{
@@ -510,7 +506,7 @@ jerry_debugger_receive (void)
uint32_t message_size = (uint32_t) (recv_buffer_p[1] & JERRY_DEBUGGER_WEBSOCKET_LENGTH_MASK);
uint32_t message_total_size = (uint32_t) (message_size + sizeof (jerry_debugger_receive_header_t));
if (JERRY_CONTEXT (debugger_receive_buffer_offset) < message_total_size)
if (offset < message_total_size)
{
if (expected_message_type != 0)
{
@@ -551,14 +547,14 @@ jerry_debugger_receive (void)
return true;
}
if (message_total_size < JERRY_CONTEXT (debugger_receive_buffer_offset))
if (message_total_size < offset)
{
memcpy (recv_buffer_p,
recv_buffer_p + message_total_size,
JERRY_CONTEXT (debugger_receive_buffer_offset) - message_total_size);
offset - message_total_size);
}
JERRY_CONTEXT (debugger_receive_buffer_offset) -= message_total_size;
JERRY_CONTEXT (debugger_receive_buffer_offset) = (uint16_t) (offset - message_total_size);
}
} /* jerry_debugger_receive */
+13 -13
View File
@@ -129,11 +129,12 @@ static bool
jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated string */
size_t eval_string_size) /**< evaluated string size */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
JERRY_ASSERT (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_VM_IGNORE));
JERRY_CONTEXT (jerry_init_flags) &= (uint32_t) ~JERRY_INIT_DEBUGGER;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_IGNORE);
ecma_value_t result = ecma_op_eval_chars_buffer (eval_string_p, eval_string_size, true, false);
JERRY_CONTEXT (jerry_init_flags) |= (uint32_t) JERRY_INIT_DEBUGGER;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_VM_IGNORE);
if (!ECMA_IS_VALUE_ERROR (result))
{
@@ -338,7 +339,7 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer the the rec
{
JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t);
JERRY_CONTEXT (debugger_stop_exec) = true;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
*resume_exec_p = false;
return true;
@@ -348,9 +349,8 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer the the rec
{
JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t);
JERRY_CONTEXT (debugger_stop_exec) = false;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
*resume_exec_p = true;
return true;
}
@@ -359,7 +359,7 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer the the rec
{
JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t);
JERRY_CONTEXT (debugger_stop_exec) = true;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = NULL;
*resume_exec_p = true;
return true;
@@ -369,7 +369,7 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer the the rec
{
JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t);
JERRY_CONTEXT (debugger_stop_exec) = true;
JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP);
JERRY_CONTEXT (debugger_stop_context) = JERRY_CONTEXT (vm_top_context_p);
*resume_exec_p = true;
return true;
@@ -444,7 +444,7 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer the the rec
void
jerry_debugger_breakpoint_hit (void)
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_breakpoint_hit_t, breakpoint_hit_p);
@@ -479,7 +479,7 @@ jerry_debugger_breakpoint_hit (void)
void
jerry_debugger_send_type (jerry_debugger_header_type_t type) /**< message type */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_type_t, message_type_p);
@@ -552,7 +552,7 @@ jerry_debugger_send_string (uint8_t message_type, /**< message type */
const uint8_t *string_p, /**< string data */
size_t string_length) /**< length of string */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
const size_t max_fragment_len = JERRY_DEBUGGER_SEND_MAX (uint8_t);
@@ -590,7 +590,7 @@ void
jerry_debugger_send_function_name (const uint8_t *function_name_p, /**< function name */
size_t function_name_length) /**< length of function name */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
jerry_debugger_send_string (JERRY_DEBUGGER_FUNCTION_NAME, function_name_p, function_name_length);
} /* jerry_debugger_send_function_name */
@@ -605,7 +605,7 @@ bool
jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, /**< message type */
ecma_compiled_code_t *compiled_code_p) /**< byte code pointer */
{
JERRY_ASSERT (JERRY_CONTEXT (jerry_init_flags) & JERRY_INIT_DEBUGGER);
JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED);
JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_byte_code_cp_t, byte_code_cp_p);
+11
View File
@@ -43,6 +43,17 @@
#define JERRY_DEBUGGER_SEND_MAX(type) \
((JERRY_DEBUGGER_MAX_SEND_SIZE - sizeof (jerry_debugger_send_header_t) - 1) / sizeof (type))
/**
* Debugger option flags.
*/
typedef enum
{
JERRY_DEBUGGER_CONNECTED = 1u << 0, /**< debugger is connected */
JERRY_DEBUGGER_VM_STOP = 1u << 1, /**< stop at the next breakpoint
* regardless it is enabled */
JERRY_DEBUGGER_VM_IGNORE = 1u << 2, /**< ignore all breakpoints */
} jerry_debugger_flags_t;
/**
* Types for the package.
*/