Followup changes in JerryScript debugger after #1910.

* Remove 'jerry_debugger_cleaup'. Do it automatically in 'jerry_cleanup'.
* Updated the documentations.
* Updated the NuttX and Artik053 targets.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó
2017-09-05 10:00:30 +02:00
committed by yichoi
parent a51def40e7
commit a54427e255
12 changed files with 110 additions and 50 deletions
+2 -2
View File
@@ -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**
+57 -7
View File
@@ -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 ();
```
-14
View File
@@ -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.
*
+7
View File
@@ -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)
+1 -3
View File
@@ -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);
/**
* @}
*/
-4
View File
@@ -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);
-7
View File
@@ -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
+1 -2
View File
@@ -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
+21 -1
View File
@@ -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);
@@ -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
@@ -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
@@ -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);