Update the webpage (#2499)

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
László Langó
2018-08-31 12:02:17 +02:00
committed by Akos Kiss
parent 2ce27a189a
commit cf87970ef6
8 changed files with 722 additions and 314 deletions
+126 -64
View File
@@ -13,24 +13,23 @@ permalink: /debugger/
JerryScript provides a remote debugger which allows debugging
JavaScript programs. The debugger has two main components:
a server which is part of the JerryScript binary and a
separate client application. Currently two debugger clients
are available in the /jerry-debugger subdirectory: an HTML
and a Python application. These simple applications demonstrate
the communication protocol between the client and server and can
be reused by integrated development environments.
separate client application. Currently a Python-based debugger
client is available in the /jerry-debugger subdirectory.
This simple application demonstrates the communication protocol
between the client and server, and can be reused by integrated
development environments.
## Setting up the debugger server
The following arguments must be passed to `tools/build.py`:
`--jerry-debugger=on --jerry-libc=off`
`--jerry-debugger=on`
At the moment only a Websocket-based implementation is provided
by JerryScript which transmits messages over TCP/IP networks.
This implementation requires a socket API which is not yet
supported by jerry-libc so the standard libc is used instead.
In the future any reliable stream or datagram based protocol
can be used for transmitting debugger messages.
The transport layer of the communication protocol is pluggable.
At the moment, a WebSocket-based implementation is provided as a
JerryScript extension, which transmits messages over TCP/IP networks.
If necessary/implemented, any reliable stream or datagram based
protocol can be used for transmitting debugger messages.
## Debugging JavaScript applications
@@ -59,8 +58,8 @@ the *Waiting for client connection* message:
`--log-level 2`
The HTML client can connect to the IP address of the server with
the `connect` command. The IP address can be localhost
The Python client can connect to the server by specifying its
IP address on the command line. The address can be localhost
if the server and the client are running on the same machine.
After the connection is established the execution can be
@@ -75,9 +74,12 @@ All available commands of the client can be queried by the
## Integrating debugger support into applications using JerryScript
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 using the extension-provided WebSocket transport layer, the
debugger can be enabled by calling `jerryx_debugger_after_connect
(jerryx_debugger_tcp_create (debug_port) && jerryx_debugger_ws_create ())`
after the `jerry_init ()` function. It initializes the debugger and
blocks until a client connects. (Custom transport layers may be
implemented and initialized similarly.)
The resource name provided to `jerry_parse ()` is used by the client
to identify the resource name of the source code. This resource name
@@ -86,7 +88,7 @@ is usually a file name.
## JerryScript debugger C-API interface
The following section describes the debugger functions
available for the host application.
available to the host application.
## JerryScript debugger types
@@ -117,36 +119,6 @@ typedef jerry_value_t
## JerryScript debugger functions
### 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**
@@ -162,10 +134,18 @@ jerry_debugger_is_connected (void);
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_debugger_init (5001);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
if (jerry_debugger_is_connected ())
{
@@ -194,10 +174,18 @@ jerry_debugger_stop (void)
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_debugger_init (5001);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_debugger_stop ();
@@ -228,10 +216,18 @@ jerry_debugger_continue (void)
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_debugger_init (5001);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_debugger_continue ();
@@ -243,7 +239,7 @@ jerry_debugger_continue (void)
- [jerry_debugger_stop](#jerry_debugger_stop)
### jerry_debugger_disable_stop_at_breakpoint
### jerry_debugger_stop_at_breakpoint
**Summary**
@@ -262,15 +258,26 @@ jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint)
**Example**
[doctest]: # (test="link")
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerry_debugger_init (5001);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_debugger_stop_at_breakpoint (true);
// Protected execution of JavaScript code.
jerry_eval (...);
const jerry_char_t script[] = "42";
size_t script_size = strlen ((const char *) script);
jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_debugger_stop_at_breakpoint (false);
@@ -298,7 +305,12 @@ jerry_debugger_wait_for_client_source (jerry_debugger_wait_for_source_callback_t
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
/**
* Runs the source code received by jerry_debugger_wait_for_client_source.
*/
@@ -325,20 +337,23 @@ wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource nam
return ret_val;
} /* wait_for_source_callback */
int main ()
int
main (void)
{
jerry_debugger_wait_for_source_status_t receive_status;
do
{
/* Create a new JerryScript instance when a context reset is
* received. Applications usually registers their core bindings
* here as well (e.g. print, setTimeout). */
jerry_init (JERRY_INIT_EMPTY);
jerry_debugger_init (5001);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
do
{
jerry_value_t run_result;
jerry_debugger_wait_for_source_status_t receive_status;
receive_status = jerry_debugger_wait_for_client_source (wait_for_source_callback,
NULL,
@@ -369,20 +384,67 @@ Sends the program's output to the debugger client.
**Prototype**
```c
void
jerry_debugger_send_output (jerry_char_t buffer[], jerry_size_t string_size, uint8_t type)
void
jerry_debugger_send_output (const jerry_char_t *buffer, jerry_size_t string_size)
```
**Example**
```c
jerry_init (JERRY_INIT_EMPTY);
jerry_debugger_init (5001);
[doctest]: # (test="link")
jerry_char_t my_output = "Hey, this should be sent too!";
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
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_debugger_send_output (my_output, my_output_size);
jerry_cleanup ();
}
```
### jerry_debugger_send_log
**Summary**
Sends the program's log to the debugger client.
**Prototype**
```c
void
jerry_debugger_send_log (jerry_log_level_t level, const jerry_char_t *buffer, jerry_size_t string_size)
```
**Example**
[doctest]: # (test="link")
```c
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
jerryx_debugger_after_connect (jerryx_debugger_tcp_create (5001)
&& jerryx_debugger_ws_create ());
jerry_char_t my_log[] = "Custom diagnostics";
jerry_size_t my_log_size = sizeof (my_log);
jerry_debugger_send_log (JERRY_LOG_LEVEL_DEBUG, my_log, my_log_size);
jerry_cleanup ();
}
```