From c8b99d05e11617ce1581634da20f4694f24d08a0 Mon Sep 17 00:00:00 2001 From: Daniel Balla Date: Wed, 6 Sep 2017 12:14:24 +0200 Subject: [PATCH] Send every kind of output to the debugger client Now correctly sending jerry_port_log output to the debugger client as well. JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu --- docs/05.PORT-API.md | 10 +++++----- docs/07.DEBUGGER.md | 1 - jerry-core/debugger/debugger.h | 6 ++++-- jerry-debugger/jerry-client-ws.html | 12 +++++++++--- jerry-debugger/jerry-client-ws.py | 11 ++++++++--- jerry-port/default/default-io.c | 18 +++++++++++++++--- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/docs/05.PORT-API.md b/docs/05.PORT-API.md index f358197b9..70ecd955e 100644 --- a/docs/05.PORT-API.md +++ b/docs/05.PORT-API.md @@ -48,10 +48,10 @@ typedef enum } jerry_log_level_t; /** - * Display or log a debug/error message. The function should implement a printf-like - * interface, where the first argument specifies the log level - * and the second argument specifies a format string on how to stringify the rest - * of the parameter list. + * Display or log a debug/error message, and sends it to the debugger client as well. + * The function should implement a printf-like interface, where the first argument + * specifies the log level and the second argument specifies a format string on how + * to stringify the rest of the parameter list. * * This function is only called with messages coming from the jerry engine as * the result of some abnormal operation or describing its internal operations @@ -230,4 +230,4 @@ jerry_port_get_current_instance (void) { return current_instance_p; } /* jerry_port_get_current_instance */ -``` \ No newline at end of file +``` diff --git a/docs/07.DEBUGGER.md b/docs/07.DEBUGGER.md index b12f5eb06..1fbf4478e 100644 --- a/docs/07.DEBUGGER.md +++ b/docs/07.DEBUGGER.md @@ -291,7 +291,6 @@ jerry_debugger_wait_and_run_client_source (jerry_value_t *return_value) **Summary** Sends the program's output to the debugger client. -At the moment only the JS print size is implemented. **Prototype** diff --git a/jerry-core/debugger/debugger.h b/jerry-core/debugger/debugger.h index 91d0828de..0181c91ad 100644 --- a/jerry-core/debugger/debugger.h +++ b/jerry-core/debugger/debugger.h @@ -162,8 +162,10 @@ typedef enum typedef enum { JERRY_DEBUGGER_OUTPUT_OK = 1, /**< output result, no error */ - JERRY_DEBUGGER_OUTPUT_WARNING = 2, /**< output result, warning */ - JERRY_DEBUGGER_OUTPUT_ERROR = 3, /**< output result, error */ + JERRY_DEBUGGER_OUTPUT_ERROR = 2, /**< output result, error */ + JERRY_DEBUGGER_OUTPUT_WARNING = 3, /**< output result, warning */ + JERRY_DEBUGGER_OUTPUT_DEBUG = 4, /**< output result, debug */ + JERRY_DEBUGGER_OUTPUT_TRACE = 5, /**< output result, trace */ } jerry_debugger_output_subtype_t; /** diff --git a/jerry-debugger/jerry-client-ws.html b/jerry-debugger/jerry-client-ws.html index 7dc2679e2..c48e06340 100644 --- a/jerry-debugger/jerry-client-ws.html +++ b/jerry-debugger/jerry-client-ws.html @@ -68,8 +68,10 @@ var JERRY_DEBUGGER_EVAL_ERROR = 2; // Subtypes of output result var JERRY_DEBUGGER_OUTPUT_OK = 1; -var JERRY_DEBUGGER_OUTPUT_WARNING = 2; -var JERRY_DEBUGGER_OUTPUT_ERROR = 3; +var JERRY_DEBUGGER_OUTPUT_ERROR = 2; +var JERRY_DEBUGGER_OUTPUT_WARNING = 3; +var JERRY_DEBUGGER_OUTPUT_DEBUG = 4; +var JERRY_DEBUGGER_OUTPUT_TRACE = 5; // Messages sent by the client to server. var JERRY_DEBUGGER_FREE_BYTE_CODE_CP = 1; @@ -944,6 +946,7 @@ function DebuggerClient(address) switch (subType) { case JERRY_DEBUGGER_OUTPUT_OK: + case JERRY_DEBUGGER_OUTPUT_DEBUG: outString = "out: " + cesu8ToString(outputResult); break; case JERRY_DEBUGGER_OUTPUT_WARNING: @@ -952,12 +955,15 @@ function DebuggerClient(address) case JERRY_DEBUGGER_OUTPUT_ERROR: outString = "err: " + cesu8ToString(outputResult); break; + case JERRY_DEBUGGER_OUTPUT_TRACE: + outString = "trace: " + cesu8ToString(outputResult); + break; } appendLog(outString); outputResult = null; } - + return; } diff --git a/jerry-debugger/jerry-client-ws.py b/jerry-debugger/jerry-client-ws.py index 27f688449..34b4cf5d1 100755 --- a/jerry-debugger/jerry-client-ws.py +++ b/jerry-debugger/jerry-client-ws.py @@ -58,8 +58,10 @@ JERRY_DEBUGGER_EVAL_ERROR = 2 # Subtypes of output JERRY_DEBUGGER_OUTPUT_OK = 1 -JERRY_DEBUGGER_OUTPUT_WARNING = 2 -JERRY_DEBUGGER_OUTPUT_ERROR = 3 +JERRY_DEBUGGER_OUTPUT_ERROR = 2 +JERRY_DEBUGGER_OUTPUT_WARNING = 3 +JERRY_DEBUGGER_OUTPUT_DEBUG = 4 +JERRY_DEBUGGER_OUTPUT_TRACE = 5 # Messages sent by the client to server. @@ -1115,12 +1117,15 @@ def main(): # Subtypes of output if buffer_type == JERRY_DEBUGGER_OUTPUT_RESULT_END: - if subtype == JERRY_DEBUGGER_OUTPUT_OK: + if subtype in [JERRY_DEBUGGER_OUTPUT_OK, + JERRY_DEBUGGER_OUTPUT_DEBUG]: print("%sout: %s%s" % (debugger.blue, debugger.nocolor, message)) elif subtype == JERRY_DEBUGGER_OUTPUT_WARNING: print("%swarning: %s%s" % (debugger.yellow, debugger.nocolor, message)) elif subtype == JERRY_DEBUGGER_OUTPUT_ERROR: print("%serr: %s%s" % (debugger.red, debugger.nocolor, message)) + elif subtype == JERRY_DEBUGGER_OUTPUT_TRACE: + print("%strace: %s%s" % (debugger.blue, debugger.nocolor, message)) # Subtypes of eval elif buffer_type == JERRY_DEBUGGER_EVAL_RESULT_END: diff --git a/jerry-port/default/default-io.c b/jerry-port/default/default-io.c index 6cca9731e..1e2f03225 100644 --- a/jerry-port/default/default-io.c +++ b/jerry-port/default/default-io.c @@ -17,6 +17,7 @@ #include "jerryscript-port.h" #include "jerryscript-port-default.h" +#include "debugger.h" #ifndef DISABLE_EXTRA_API @@ -60,9 +61,10 @@ jerry_port_default_set_log_level (jerry_log_level_t level) /**< log level */ #endif /* !DISABLE_EXTRA_API */ /** - * Default implementation of jerry_port_log. Prints log message to standard - * error with 'vfprintf' if message level is less than or equal to the set log - * level. + * Default implementation of jerry_port_log. Prints log message to a buffer + * then prints the buffer to the standard error with 'fprintf' if message + * level is less than or equal to the set log level. + * Additionally, sends the message to the debugger client. * * Note: * Changing the log level from JERRY_LOG_LEVEL_ERROR is only possible if @@ -78,7 +80,17 @@ jerry_port_log (jerry_log_level_t level, /**< log level */ { va_list args; va_start (args, format); +#ifdef JERRY_DEBUGGER + char buffer[256]; + int length = 0; + length = vsnprintf (buffer, 255, format, args); + buffer[length] = '\0'; + fprintf (stderr, "%s", buffer); + jerry_char_t *jbuffer = (jerry_char_t *) buffer; + jerry_debugger_send_output (jbuffer, (jerry_size_t) length, (uint8_t) (level + 2)); +#else /* If jerry-debugger isn't defined, libc is turned on */ vfprintf (stderr, format, args); +#endif /* JERRY_DEBUGGER */ va_end (args); } } /* jerry_port_log */