diff --git a/docs/02.API-REFERENCE.md b/docs/02.API-REFERENCE.md index 8ae5e6fa3..1cfb909c0 100644 --- a/docs/02.API-REFERENCE.md +++ b/docs/02.API-REFERENCE.md @@ -9,7 +9,7 @@ Enum that contains the following elements: - JERRY_INIT_SHOW_REGEXP_OPCODES - dump regexp byte-code to log after compilation - JERRY_INIT_MEM_STATS - dump memory statistics - JERRY_INIT_MEM_STATS_SEPARATE - dump memory statistics and reset peak values after parse - - JERRY_INIT_DEBUGGER - enable all features required by debugging + - JERRY_INIT_DEBUGGER - deprecated, an unused placeholder now ## jerry_error_t @@ -319,7 +319,7 @@ jerry_init (jerry_init_flag_t flags) - `JERRY_INIT_SHOW_REGEXP_OPCODES` - print compiled regexp byte-code. - `JERRY_INIT_MEM_STATS` - dump memory statistics. - `JERRY_INIT_MEM_STATS_SEPARATE` - dump memory statistics and reset peak values after parse. -- `JERRY_INIT_DEBUGGER` - enable all features required by debugging. +- `JERRY_INIT_DEBUGGER` - deprecated, an unused placeholder now **Example** diff --git a/docs/07.DEBUGGER.md b/docs/07.DEBUGGER.md index 465468aae..b12f5eb06 100644 --- a/docs/07.DEBUGGER.md +++ b/docs/07.DEBUGGER.md @@ -65,8 +65,8 @@ All available commands of the client can be queried by the ## Integrating debugger support into applications using JerryScript -The debugger can be enabled by passing the `JERRY_INIT_DEBUGGER` flag -to the `jerry_init ()` function which then initializes the debugger +The debugger can be enabled by calling the `jerry_debugger_init (uint16_t port)` +function after the `jerry_init ()` function. It initializes the debugger and blocks until a client connects. When the debugger is enabled it is recommended to use @@ -83,6 +83,36 @@ debugger is disabled. The following section describes the debugger functions available for the host application. +### jerry_debugger_init + +**Summary** + +Debugger server initialization. Must be called after `jerry_init`. + +**Prototype** + +```c +void +jerry_debugger_init (uint16_t port); +``` + +- `port` - Server port number + + +**Example** + +```c +{ + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); + + // ... + + jerry_cleanup (); +} +``` + + ### jerry_debugger_is_connected **Summary** @@ -100,12 +130,15 @@ jerry_debugger_is_connected (void); ```c { - jerry_init (JERRY_INIT_DEBUGGER); + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); if (jerry_debugger_is_connected ()) { printf ("A remote debugger client is connected."); } + + jerry_cleanup (); } ``` @@ -129,9 +162,12 @@ jerry_debugger_stop (void) ```c { - jerry_init (JERRY_INIT_DEBUGGER); + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); jerry_debugger_stop (); + + jerry_cleanup (); } ``` @@ -160,9 +196,12 @@ jerry_debugger_continue (void) ```c { - jerry_init (JERRY_INIT_DEBUGGER); + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); jerry_debugger_continue (); + + jerry_cleanup (); } ``` @@ -191,7 +230,8 @@ jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint) ```c { - jerry_init (JERRY_INIT_DEBUGGER); + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); jerry_debugger_stop_at_breakpoint (true); @@ -199,6 +239,8 @@ jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint) jerry_eval (...); jerry_debugger_stop_at_breakpoint (false); + + jerry_cleanup (); } ``` @@ -221,7 +263,8 @@ jerry_debugger_wait_and_run_client_source (jerry_value_t *return_value) **Example** ```c - jerry_init (JERRY_INIT_DEBUGGER); + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); jerry_value_t run_result; jerry_debugger_wait_and_run_type_t receive_status; @@ -239,6 +282,8 @@ jerry_debugger_wait_and_run_client_source (jerry_value_t *return_value) jerry_release_value (run_result); } while (receive_status == JERRY_DEBUGGER_SOURCE_RECEIVED); + + jerry_cleanup (); ``` ### jerry_debugger_send_output @@ -258,8 +303,13 @@ At the moment only the JS print size is implemented. **Example** ```c + jerry_init (JERRY_INIT_EMPTY); + jerry_debugger_init (5001); + jerry_char_t my_output = "Hey, this should be sent too!"; jerry_size_t my_output_size = sizeof (my_output); jerry_debugger_send_output (my_output, my_output_size, JERRY_DEBUGGER_OUTPUT_OK); + + jerry_cleanup (); ``` diff --git a/jerry-core/api/jerry-debugger.c b/jerry-core/api/jerry-debugger.c index aa6984495..f64e1f9c3 100644 --- a/jerry-core/api/jerry-debugger.c +++ b/jerry-core/api/jerry-debugger.c @@ -103,20 +103,6 @@ jerry_debugger_init (uint16_t port) /**< server port number */ #endif /* JERRY_DEBUGGER */ } /* jerry_debugger_init */ -/** - * Debugger server shutdown. Must be called before jerry_cleanup. - */ -void -jerry_debugger_cleanup (void) -{ -#ifdef JERRY_DEBUGGER - if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) - { - jerry_debugger_close_connection (); - } -#endif /* JERRY_DEBUGGER */ -} /* jerry_debugger_cleanup */ - /** * Sets whether the engine should wait and run a source. * diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c index 5a35032af..4499ae0a7 100644 --- a/jerry-core/api/jerry.c +++ b/jerry-core/api/jerry.c @@ -167,6 +167,13 @@ jerry_cleanup (void) { jerry_assert_api_available (); +#ifdef JERRY_DEBUGGER + if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) + { + jerry_debugger_close_connection (); + } +#endif /* JERRY_DEBUGGER */ + for (jerry_context_data_header_t *this_p = JERRY_CONTEXT (context_data_p), *next_p = NULL; this_p != NULL; this_p = next_p) diff --git a/jerry-core/include/jerryscript-debugger.h b/jerry-core/include/jerryscript-debugger.h index 730504bd2..c4f01e0dc 100644 --- a/jerry-core/include/jerryscript-debugger.h +++ b/jerry-core/include/jerryscript-debugger.h @@ -40,6 +40,7 @@ typedef enum /** * Engine debugger functions. */ +void jerry_debugger_init (uint16_t port); bool jerry_debugger_is_connected (void); void jerry_debugger_stop (void); void jerry_debugger_continue (void); @@ -47,9 +48,6 @@ void jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint); jerry_debugger_wait_and_run_type_t jerry_debugger_wait_and_run_client_source (jerry_value_t *return_value); void jerry_debugger_send_output (jerry_char_t buffer[], jerry_size_t str_size, uint8_t type); -void jerry_debugger_init (uint16_t port); -void jerry_debugger_cleanup (void); - /** * @} */ diff --git a/jerry-main/main-unix.c b/jerry-main/main-unix.c index 42e98db81..c7afe1b1a 100644 --- a/jerry-main/main-unix.c +++ b/jerry-main/main-unix.c @@ -830,10 +830,6 @@ main (int argc, jerry_release_value (ret_value); - if (start_debug_server) - { - jerry_debugger_cleanup (); - } jerry_cleanup (); #ifdef JERRY_ENABLE_EXTERNAL_CONTEXT free (instance_p); diff --git a/targets/nuttx-stm32f4/Kconfig b/targets/nuttx-stm32f4/Kconfig index 6f8ff369a..0682aaff6 100644 --- a/targets/nuttx-stm32f4/Kconfig +++ b/targets/nuttx-stm32f4/Kconfig @@ -46,11 +46,4 @@ config JERRYSCRIPT_SHOW_OPCODES config JERRYSCRIPT_DEBUGGER bool "Jerryscript debugger" default n - -if JERRYSCRIPT_DEBUGGER -config JERRYSCRIPT_DEBUGGER_PORT - int "Jerryscript debugger port" - default 5001 -endif - endif diff --git a/targets/nuttx-stm32f4/Makefile b/targets/nuttx-stm32f4/Makefile index e35c6095b..46077c763 100644 --- a/targets/nuttx-stm32f4/Makefile +++ b/targets/nuttx-stm32f4/Makefile @@ -19,7 +19,6 @@ CONFIG_JERRYSCRIPT_PRIORITY ?= SCHED_PRIORITY_DEFAULT CONFIG_JERRYSCRIPT_STACKSIZE ?= 16384 CONFIG_JERRYSCRIPT_HEAPSIZE ?= 107520 -CONFIG_JERRY_DEBUGGER_PORT ?= 5001 APPNAME = jerry # path to the project dir, "jerry-nuttx" by default @@ -45,7 +44,7 @@ ifeq ($(CONFIG_JERRYSCRIPT_SHOW_OPCODES),y) endif ifeq ($(CONFIG_JERRYSCRIPT_DEBUGGER),y) - CFLAGS += -DJERRY_DEBUGGER '-DJERRY_DEBUGGER_PORT=$(CONFIG_JERRY_DEBUGGER_PORT)' + CFLAGS += -DJERRY_DEBUGGER endif # Jerryscript diff --git a/targets/nuttx-stm32f4/jerry_main.c b/targets/nuttx-stm32f4/jerry_main.c index de36b4ec7..97f4d52e6 100644 --- a/targets/nuttx-stm32f4/jerry_main.c +++ b/targets/nuttx-stm32f4/jerry_main.c @@ -53,6 +53,7 @@ print_help (char *name) " --mem-stats-separate\n" " --show-opcodes\n" " --start-debug-server\n" + " --debug-server-port [port]\n" "\n", name); } /* print_help */ @@ -357,6 +358,8 @@ int jerry_main (int argc, char *argv[]) const char *file_names[JERRY_MAX_COMMAND_LINE_ARGS]; int i; int files_counter = 0; + bool start_debug_server = false; + uint16_t debug_port = 5001; jerry_init_flag_t flags = JERRY_INIT_EMPTY; @@ -396,7 +399,19 @@ int jerry_main (int argc, char *argv[]) } else if (!strcmp ("--start-debug-server", argv[i])) { - flags |= JERRY_INIT_DEBUGGER; + start_debug_server = true; + } + else if (!strcmp ("--debug-server-port", argv[i])) + { + if (++i < argc) + { + debug_port = str_to_uint (argv[i]); + } + else + { + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: wrong format or invalid argument\n"); + return JERRY_STANDALONE_EXIT_CODE_FAIL; + } } else { @@ -406,6 +421,11 @@ int jerry_main (int argc, char *argv[]) jerry_init (flags); + if (start_debug_server) + { + jerry_debugger_init (debug_port); + } + register_js_function ("assert", jerryx_handler_assert); register_js_function ("gc", jerryx_handler_gc); register_js_function ("print", jerryx_handler_print); diff --git a/targets/tizenrt-artik053/apps/jerryscript/Kconfig b/targets/tizenrt-artik053/apps/jerryscript/Kconfig index 6f8ff369a..0682aaff6 100644 --- a/targets/tizenrt-artik053/apps/jerryscript/Kconfig +++ b/targets/tizenrt-artik053/apps/jerryscript/Kconfig @@ -46,11 +46,4 @@ config JERRYSCRIPT_SHOW_OPCODES config JERRYSCRIPT_DEBUGGER bool "Jerryscript debugger" default n - -if JERRYSCRIPT_DEBUGGER -config JERRYSCRIPT_DEBUGGER_PORT - int "Jerryscript debugger port" - default 5001 -endif - endif diff --git a/targets/tizenrt-artik053/apps/jerryscript/Makefile b/targets/tizenrt-artik053/apps/jerryscript/Makefile index 0d5e2d553..0b166a895 100644 --- a/targets/tizenrt-artik053/apps/jerryscript/Makefile +++ b/targets/tizenrt-artik053/apps/jerryscript/Makefile @@ -72,7 +72,6 @@ include $(APPDIR)/Make.defs CONFIG_JERRYSCRIPT_PRIORITY ?= SCHED_PRIORITY_DEFAULT CONFIG_JERRYSCRIPT_STACKSIZE ?= 32768 CONFIG_JERRYSCRIPT_HEAPSIZE ?= 64000 -CONFIG_JERRY_DEBUGGER_PORT ?= 5001 APPNAME = jerry # path to the project dir, "tizenrt-artik053" by default @@ -92,7 +91,7 @@ ifeq ($(CONFIG_JERRYSCRIPT_SHOW_OPCODES),y) endif ifeq ($(CONFIG_JERRYSCRIPT_DEBUGGER),y) - CFLAGS += -DJERRY_DEBUGGER '-DJERRY_DEBUGGER_PORT=$(CONFIG_JERRY_DEBUGGER_PORT)' + CFLAGS += -DJERRY_DEBUGGER endif diff --git a/targets/tizenrt-artik053/apps/jerryscript/jerry_main.c b/targets/tizenrt-artik053/apps/jerryscript/jerry_main.c index 9ea520230..21c33bb7c 100644 --- a/targets/tizenrt-artik053/apps/jerryscript/jerry_main.c +++ b/targets/tizenrt-artik053/apps/jerryscript/jerry_main.c @@ -333,6 +333,8 @@ jerry_cmd_main (int argc, char *argv[]) const char *file_names[JERRY_MAX_COMMAND_LINE_ARGS]; int i; int files_counter = 0; + bool start_debug_server = false; + uint16_t debug_port = 5001; jerry_init_flag_t flags = JERRY_INIT_EMPTY; @@ -372,7 +374,19 @@ jerry_cmd_main (int argc, char *argv[]) } else if (!strcmp ("--start-debug-server", argv[i])) { - flags |= JERRY_INIT_DEBUGGER; + start_debug_server = true; + } + else if (!strcmp ("--debug-server-port", argv[i])) + { + if (++i < argc) + { + debug_port = str_to_uint (argv[i]); + } + else + { + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: wrong format or invalid argument\n"); + return JERRY_STANDALONE_EXIT_CODE_FAIL; + } } else { @@ -382,6 +396,11 @@ jerry_cmd_main (int argc, char *argv[]) jerry_init (flags); + if (start_debug_server) + { + jerry_debugger_init (debug_port); + } + register_js_function ("assert", jerryx_handler_assert); register_js_function ("gc", jerryx_handler_gc); register_js_function ("print", jerryx_handler_print);