Reworking jerry_debugger_send_string method

From now on, jerry_debugger_send_string can send a subtype of the string, making it more simple to send over strings with special parameters, therefore seperating different types of messages are simpler.
Enumerations for various subtypes can be made, while there's only need to have 2 entries for the header type.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
This commit is contained in:
Daniel Balla
2017-08-07 10:33:50 +02:00
committed by yichoi
parent ad608e30dc
commit a48f24f8da
7 changed files with 60 additions and 24 deletions
+4 -1
View File
@@ -389,7 +389,10 @@ jerry_parse_named_resource (const jerry_char_t *name_p, /**< name (usually a fil
#ifdef JERRY_DEBUGGER #ifdef JERRY_DEBUGGER
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{ {
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME, name_p, name_length); jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
name_p,
name_length);
} }
#else /* JERRY_DEBUGGER */ #else /* JERRY_DEBUGGER */
JERRY_UNUSED (name_p); JERRY_UNUSED (name_p);
+15 -3
View File
@@ -160,7 +160,7 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
} }
ecma_value_t message = result; ecma_value_t message = result;
uint8_t type = JERRY_DEBUGGER_EVAL_RESULT; uint8_t type = JERRY_DEBUGGER_EVAL_OK;
if (ECMA_IS_VALUE_ERROR (result)) if (ECMA_IS_VALUE_ERROR (result))
{ {
@@ -183,7 +183,8 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
ecma_free_value (result); ecma_free_value (result);
const lit_utf8_byte_t *string_p = lit_get_magic_string_utf8 (id); const lit_utf8_byte_t *string_p = lit_get_magic_string_utf8 (id);
return jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_ERROR, return jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_RESULT,
type,
string_p, string_p,
strlen ((const char *) string_p)); strlen ((const char *) string_p));
} }
@@ -201,7 +202,7 @@ jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated s
ecma_string_t *string_p = ecma_get_string_from_value (message); ecma_string_t *string_p = ecma_get_string_from_value (message);
ECMA_STRING_TO_UTF8_STRING (string_p, buffer_p, buffer_size); ECMA_STRING_TO_UTF8_STRING (string_p, buffer_p, buffer_size);
bool success = jerry_debugger_send_string (type, buffer_p, buffer_size); bool success = jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_RESULT, type, buffer_p, buffer_size);
ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size); ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size);
ecma_free_value (message); ecma_free_value (message);
@@ -702,6 +703,7 @@ jerry_debugger_send_data (jerry_debugger_header_type_t type, /**< message type *
*/ */
bool bool
jerry_debugger_send_string (uint8_t message_type, /**< message type */ jerry_debugger_send_string (uint8_t message_type, /**< message type */
uint8_t sub_type, /**< subtype of the string */
const uint8_t *string_p, /**< string data */ const uint8_t *string_p, /**< string data */
size_t string_length) /**< length of string */ size_t string_length) /**< length of string */
{ {
@@ -728,10 +730,19 @@ jerry_debugger_send_string (uint8_t message_type, /**< message type */
string_p += max_fragment_len; string_p += max_fragment_len;
} }
if (sub_type != JERRY_DEBUGGER_NO_SUBTYPE)
{
string_length += 1;
}
JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE (message_string_p, 1 + string_length); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE (message_string_p, 1 + string_length);
message_string_p->type = (uint8_t) (message_type + 1); message_string_p->type = (uint8_t) (message_type + 1);
memcpy (message_string_p->string, string_p, string_length); memcpy (message_string_p->string, string_p, string_length);
if (sub_type != JERRY_DEBUGGER_NO_SUBTYPE)
{
message_string_p->string[string_length - 1] = sub_type;
}
return jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + string_length); return jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + string_length);
} /* jerry_debugger_send_string */ } /* jerry_debugger_send_string */
@@ -960,6 +971,7 @@ jerry_debugger_send_exception_string (ecma_value_t exception_value) /**< error v
ECMA_STRING_TO_UTF8_STRING (string_p, string_data_p, string_size); ECMA_STRING_TO_UTF8_STRING (string_p, string_data_p, string_size);
bool result = jerry_debugger_send_string (JERRY_DEBUGGER_EXCEPTION_STR, bool result = jerry_debugger_send_string (JERRY_DEBUGGER_EXCEPTION_STR,
JERRY_DEBUGGER_NO_SUBTYPE,
string_data_p, string_data_p,
string_size); string_size);
+15 -3
View File
@@ -33,6 +33,11 @@
*/ */
#define JERRY_DEBUGGER_TIMEOUT 100 #define JERRY_DEBUGGER_TIMEOUT 100
/**
* This constant represents that the string to be sent has no subtype.
*/
#define JERRY_DEBUGGER_NO_SUBTYPE 0
/** /**
* Limited resources available for the engine, so it is important to * Limited resources available for the engine, so it is important to
* check the maximum buffer size. It needs to be between 64 and 256 bytes. * check the maximum buffer size. It needs to be between 64 and 256 bytes.
@@ -114,8 +119,6 @@ typedef enum
JERRY_DEBUGGER_BACKTRACE_END = 20, /**< last backtrace data */ JERRY_DEBUGGER_BACKTRACE_END = 20, /**< last backtrace data */
JERRY_DEBUGGER_EVAL_RESULT = 21, /**< eval result */ JERRY_DEBUGGER_EVAL_RESULT = 21, /**< eval result */
JERRY_DEBUGGER_EVAL_RESULT_END = 22, /**< last part of eval result */ JERRY_DEBUGGER_EVAL_RESULT_END = 22, /**< last part of eval result */
JERRY_DEBUGGER_EVAL_ERROR = 23, /**< eval result when an error is occured */
JERRY_DEBUGGER_EVAL_ERROR_END = 24, /**< last part of eval result when an error is occured */
/* Messages sent by the client to server. */ /* Messages sent by the client to server. */
@@ -139,6 +142,15 @@ typedef enum
JERRY_DEBUGGER_EVAL_PART = 13, /**< next message of evaluating a string */ JERRY_DEBUGGER_EVAL_PART = 13, /**< next message of evaluating a string */
} jerry_debugger_header_type_t; } jerry_debugger_header_type_t;
/**
* Subtypes of send_eval.
*/
typedef enum
{
JERRY_DEBUGGER_EVAL_OK = 1, /**< eval result, no error */
JERRY_DEBUGGER_EVAL_ERROR = 2, /**< eval result when an error is occured */
} jerry_debugger_eval_subtype_t;
/** /**
* Delayed free of byte code data. * Delayed free of byte code data.
*/ */
@@ -318,7 +330,7 @@ void jerry_debugger_breakpoint_hit (uint8_t message_type);
void jerry_debugger_send_type (jerry_debugger_header_type_t type); void jerry_debugger_send_type (jerry_debugger_header_type_t type);
bool jerry_debugger_send_configuration (uint8_t max_message_size); bool jerry_debugger_send_configuration (uint8_t max_message_size);
void jerry_debugger_send_data (jerry_debugger_header_type_t type, const void *data, size_t size); void jerry_debugger_send_data (jerry_debugger_header_type_t type, const void *data, size_t size);
bool jerry_debugger_send_string (uint8_t message_type, const uint8_t *string_p, size_t string_length); bool jerry_debugger_send_string (uint8_t message_type, uint8_t sub_type, const uint8_t *string_p, size_t string_length);
bool jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, ecma_compiled_code_t *compiled_code_p); bool jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, ecma_compiled_code_t *compiled_code_p);
bool jerry_debugger_send_parse_function (uint32_t line, uint32_t column); bool jerry_debugger_send_parse_function (uint32_t line, uint32_t column);
void jerry_debugger_send_memstats (void); void jerry_debugger_send_memstats (void);
+1
View File
@@ -406,6 +406,7 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{ {
jerry_debugger_send_string (JERRY_DEBUGGER_FUNCTION_NAME, jerry_debugger_send_string (JERRY_DEBUGGER_FUNCTION_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
name_p->u.char_p, name_p->u.char_p,
name_p->prop.length); name_p->prop.length);
+5 -1
View File
@@ -2194,6 +2194,7 @@ parser_parse_function (parser_context_t *context_p, /**< context */
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{ {
jerry_debugger_send_string (JERRY_DEBUGGER_FUNCTION_NAME, jerry_debugger_send_string (JERRY_DEBUGGER_FUNCTION_NAME,
JERRY_DEBUGGER_NO_SUBTYPE,
context_p->lit_object.literal_p->u.char_p, context_p->lit_object.literal_p->u.char_p,
context_p->lit_object.literal_p->prop.length); context_p->lit_object.literal_p->prop.length);
} }
@@ -2489,7 +2490,10 @@ parser_parse_script (const uint8_t *source_p, /**< source code */
#ifdef JERRY_DEBUGGER #ifdef JERRY_DEBUGGER
if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
{ {
jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE, source_p, size); jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE,
JERRY_DEBUGGER_NO_SUBTYPE,
source_p,
size);
} }
#endif /* JERRY_DEBUGGER */ #endif /* JERRY_DEBUGGER */
+10 -7
View File
@@ -35,6 +35,7 @@ textarea {
<div> <div>
</div> </div>
<script> <script>
// Messages sent by the server to client.
var JERRY_DEBUGGER_CONFIGURATION = 1; var JERRY_DEBUGGER_CONFIGURATION = 1;
var JERRY_DEBUGGER_PARSE_ERROR = 2; var JERRY_DEBUGGER_PARSE_ERROR = 2;
var JERRY_DEBUGGER_BYTE_CODE_CP = 3; var JERRY_DEBUGGER_BYTE_CODE_CP = 3;
@@ -57,9 +58,12 @@ var JERRY_DEBUGGER_BACKTRACE = 19;
var JERRY_DEBUGGER_BACKTRACE_END = 20; var JERRY_DEBUGGER_BACKTRACE_END = 20;
var JERRY_DEBUGGER_EVAL_RESULT = 21; var JERRY_DEBUGGER_EVAL_RESULT = 21;
var JERRY_DEBUGGER_EVAL_RESULT_END = 22; var JERRY_DEBUGGER_EVAL_RESULT_END = 22;
var JERRY_DEBUGGER_EVAL_ERROR = 23;
var JERRY_DEBUGGER_EVAL_ERROR_END = 24;
// Subtypes of eval
var JERRY_DEBUGGER_EVAL_OK = 1;
var JERRY_DEBUGGER_EVAL_ERROR = 2;
// Messages sent by the client to server.
var JERRY_DEBUGGER_FREE_BYTE_CODE_CP = 1; var JERRY_DEBUGGER_FREE_BYTE_CODE_CP = 1;
var JERRY_DEBUGGER_UPDATE_BREAKPOINT = 2; var JERRY_DEBUGGER_UPDATE_BREAKPOINT = 2;
var JERRY_DEBUGGER_EXCEPTION_CONFIG = 3; var JERRY_DEBUGGER_EXCEPTION_CONFIG = 3;
@@ -896,19 +900,18 @@ function DebuggerClient(address)
case JERRY_DEBUGGER_EVAL_RESULT: case JERRY_DEBUGGER_EVAL_RESULT:
case JERRY_DEBUGGER_EVAL_RESULT_END: case JERRY_DEBUGGER_EVAL_RESULT_END:
case JERRY_DEBUGGER_EVAL_ERROR:
case JERRY_DEBUGGER_EVAL_ERROR_END:
{ {
evalResult = concatUint8Arrays(evalResult, message); evalResult = concatUint8Arrays(evalResult, message);
var subType = evalResult[evalResult.length - 1];
if (message[0] == JERRY_DEBUGGER_EVAL_RESULT_END) evalResult = evalResult.slice(0, -1);
if (subType == JERRY_DEBUGGER_EVAL_OK)
{ {
appendLog(cesu8ToString(evalResult)); appendLog(cesu8ToString(evalResult));
evalResult = null; evalResult = null;
return; return;
} }
if (message[0] == JERRY_DEBUGGER_EVAL_ERROR_END) if (subType == JERRY_DEBUGGER_EVAL_ERROR)
{ {
appendLog("Uncaught exception: " + cesu8ToString(evalResult)); appendLog("Uncaught exception: " + cesu8ToString(evalResult));
evalResult = null; evalResult = null;
+9 -8
View File
@@ -48,8 +48,10 @@ JERRY_DEBUGGER_BACKTRACE = 19
JERRY_DEBUGGER_BACKTRACE_END = 20 JERRY_DEBUGGER_BACKTRACE_END = 20
JERRY_DEBUGGER_EVAL_RESULT = 21 JERRY_DEBUGGER_EVAL_RESULT = 21
JERRY_DEBUGGER_EVAL_RESULT_END = 22 JERRY_DEBUGGER_EVAL_RESULT_END = 22
JERRY_DEBUGGER_EVAL_ERROR = 23
JERRY_DEBUGGER_EVAL_ERROR_END = 24 # Subtypes of eval
JERRY_DEBUGGER_EVAL_OK = 1
JERRY_DEBUGGER_EVAL_ERROR = 2
# Messages sent by the client to server. # Messages sent by the client to server.
@@ -1064,17 +1066,16 @@ def main():
prompt.cmdloop() prompt.cmdloop()
elif buffer_type in [JERRY_DEBUGGER_EVAL_RESULT, elif buffer_type in [JERRY_DEBUGGER_EVAL_RESULT,
JERRY_DEBUGGER_EVAL_RESULT_END, JERRY_DEBUGGER_EVAL_RESULT_END]:
JERRY_DEBUGGER_EVAL_ERROR,
JERRY_DEBUGGER_EVAL_ERROR_END]:
message = b"" message = b""
eval_type = buffer_type eval_type = buffer_type
while True: while True:
message += data[3:] message += data[3:]
if buffer_type in [JERRY_DEBUGGER_EVAL_RESULT_END, if buffer_type == JERRY_DEBUGGER_EVAL_RESULT_END:
JERRY_DEBUGGER_EVAL_ERROR_END]: subtype = ord(message[-1])
message = message[:-1]
break break
data = debugger.get_message(True) data = debugger.get_message(True)
@@ -1085,7 +1086,7 @@ def main():
eval_type + 1]: eval_type + 1]:
raise Exception("Eval result expected") raise Exception("Eval result expected")
if buffer_type == JERRY_DEBUGGER_EVAL_ERROR_END: if subtype == JERRY_DEBUGGER_EVAL_ERROR:
print("Uncaught exception: %s" % (message)) print("Uncaught exception: %s" % (message))
else: else:
print(message) print(message)