Skip to content

Commit 3595892

Browse files
author
Levente Orban
committed
Initial version of JerryScript debugger
The debugger supports setting breakpoints, execution control (step, next, continue) and getting backtrace. The communication is websocket based, so a browser can communicate with JerryScript without any intermediate application. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected] JerryScript-DCO-1.0-Signed-off-by: Levente Orban [email protected]
1 parent 66683e5 commit 3595892

39 files changed

+4166
-5
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ sudo: required
66

77
env:
88
- OPTS="--check-signed-off-travis --check-cppcheck --check-doxygen --check-vera --check-license"
9+
- OPTS="--jerry-debugger"
910
- OPTS="--jerry-tests --jerry-test-suite"
1011
- OPTS="--jerry-tests --jerry-test-suite --toolchain=cmake/toolchain_linux_armv7l.cmake" TIMEOUT=300 INSTALL_QEMU_ARM=yes
1112
- OPTS="--buildoption-test"

docs/02.API-REFERENCE.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Enum that contains the following elements:
99
- JERRY_INIT_SHOW_REGEXP_OPCODES - dump regexp byte-code to log after compilation
1010
- JERRY_INIT_MEM_STATS - dump memory statistics
1111
- JERRY_INIT_MEM_STATS_SEPARATE - dump memory statistics and reset peak values after parse
12+
- JERRY_INIT_DEBUGGER - enable all features required by debugging
1213

1314
## jerry_error_t
1415

@@ -211,6 +212,7 @@ jerry_init (jerry_init_flag_t flags)
211212
- `JERRY_INIT_SHOW_REGEXP_OPCODES` - print compiled regexp byte-code.
212213
- `JERRY_INIT_MEM_STATS` - dump memory statistics.
213214
- `JERRY_INIT_MEM_STATS_SEPARATE` - dump memory statistics and reset peak values after parse.
215+
- `JERRY_INIT_DEBUGGER` - enable all features required by debugging.
214216

215217
**Example**
216218

@@ -451,6 +453,40 @@ jerry_parse (const jerry_char_t *source_p,
451453

452454
- [jerry_run](#jerry_run)
453455

456+
## jerry_parse_named_resource
457+
458+
**Summary**
459+
460+
Parse script and construct an ECMAScript function. The lexical
461+
environment is set to the global lexical environment. The name
462+
(usually a file name) is also passed to this function which is
463+
used by the debugger to find the source code.
464+
465+
*Note*: The returned value must be freed with [jerry_release_value](#jerry_release_value) when it
466+
is no longer needed.
467+
468+
**Prototype**
469+
470+
```c
471+
jerry_value_t
472+
jerry_parse_named_resource (const jerry_char_t *name_p, /**< name (usually a file name) */
473+
size_t name_length, /**< length of name */
474+
const jerry_char_t *source_p, /**< script source */
475+
size_t source_size, /**< script source size */
476+
bool is_strict) /**< strict mode */
477+
{
478+
```
479+
480+
- `name_p` - name, usually a file name
481+
- `name_length` - size of the file name, in bytes
482+
- `source_p` - string, containing source code to parse. It must be a valid UTF8 string
483+
- `source_size` - size of the string, in bytes
484+
- `is_strict` - defines strict mode
485+
- return value
486+
- function object value, if script was parsed successfully,
487+
- thrown error, otherwise
488+
489+
This function is identical to [jerry_parse](#jerry_parse), except that an additional filename parameter has been added.
454490

455491
## jerry_run
456492

docs/07.DEBUGGER.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## JerryScript debugger interface
2+
3+
JerryScript provides a remote debugger which allows debugging
4+
JavaScript programs. The debugger has two main components:
5+
a server which is part of the JerryScript binary and a
6+
separate client application. Currently two debugger clients
7+
are available in the /jerry-debugger subdirectory: an HTML
8+
and a Python application. These simple applications demonstrate
9+
the communication protocol between the client and server and can
10+
be reused by integrated development environments.
11+
12+
## Setting up the debugger server
13+
14+
The following arguments must be passed to `tools/build.py`:
15+
16+
`--jerry-debugger=on --jerry-libc=off`
17+
18+
At the moment only a Websocket-based implementation is provided
19+
by JerryScript which transmits messages over TCP/IP networks.
20+
This implementation requires a socket API which is not yet
21+
supported by jerry-libc so the standard libc is used instead.
22+
In the future any reliable stream or datagram based protocol
23+
can be used for transmitting debugger messages.
24+
25+
## Debugging JavaScript applications
26+
27+
The debugger client must be connected to the server before the
28+
JavaScript application runs. On-the-fly attachment is not supported
29+
because the debugging information (e.g. line index of each possible
30+
breakpoint location) is not preserved by JerryScript. The client is
31+
expected to be run on a system with much more resources and it should
32+
be capable of storing this information. JerryScript frees all debug
33+
information after it is transmitted to the client to save memory.
34+
35+
The following argument makes JerryScript wait for a client
36+
connection:
37+
38+
`--start-debug-server`
39+
40+
It is also recommended to increase the log level to see
41+
the *Waiting for client connection* message:
42+
43+
`--log-level 2`
44+
45+
The HTML client can connect to the IP address of the server with
46+
the `connect` command. The IP address can be localhost
47+
if the server and the client are running on the same machine.
48+
49+
After the connection is established the execution can be
50+
controlled by the debugger. The debugger always stops at
51+
the first possible breakpoint location. The effect is the
52+
same as using the `stop` command. This allows inserting
53+
breakpoints right before the meaningful part of the execution
54+
starts.
55+
56+
All available commands of the client can be queried by the
57+
`help` command.
58+
59+
## Integrating debugger support into applications using JerryScript
60+
61+
The debugger can be enabled by passing the `JERRY_INIT_DEBUGGER` flag
62+
to the `jerry_init ()` function which then initializes the debugger
63+
and blocks until a client connects.
64+
65+
When the debugger is enabled it is recommended to use
66+
`jerry_parse_named_resource ()` instead of `jerry_parse ()` because
67+
the resource name (usually a file name) is also passed to this
68+
function. This resource name is used by the client to identify
69+
the corresponding resource. In general it is always recommended to
70+
use `jerry_parse_named_resource ()` when the resource name is
71+
available because it silently ignores the resource name if the
72+
debugger is disabled.

jerry-core/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ project (${JERRY_CORE_NAME} C)
1818

1919
# Optional features
2020
set(FEATURE_CPOINTER_32_BIT OFF CACHE BOOL "Enable 32 bit compressed pointers?")
21+
set(FEATURE_DEBUGGER OFF CACHE BOOL "Enable JerryScript debugger?")
2122
set(FEATURE_ERROR_MESSAGES OFF CACHE BOOL "Enable error messages?")
2223
set(FEATURE_JS_PARSER ON CACHE BOOL "Enable js-parser?")
2324
set(FEATURE_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
@@ -38,6 +39,7 @@ endif()
3839

3940
# Status messages
4041
message(STATUS "FEATURE_CPOINTER_32_BIT " ${FEATURE_CPOINTER_32_BIT})
42+
message(STATUS "FEATURE_DEBUGGER " ${FEATURE_DEBUGGER})
4143
message(STATUS "FEATURE_ERROR_MESSAGES " ${FEATURE_ERROR_MESSAGES})
4244
message(STATUS "FEATURE_JS_PARSER " ${FEATURE_JS_PARSER})
4345
message(STATUS "FEATURE_MEM_STATS " ${FEATURE_MEM_STATS})
@@ -55,6 +57,7 @@ message(STATUS "MEM_HEAP_SIZE_KB " ${MEM_HEAP_SIZE_KB})
5557
# Include directories
5658
set(INCLUDE_CORE
5759
"${CMAKE_CURRENT_SOURCE_DIR}"
60+
"${CMAKE_CURRENT_SOURCE_DIR}/debugger"
5861
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/base"
5962
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects"
6063
"${CMAKE_CURRENT_SOURCE_DIR}/ecma/builtin-objects/typedarray"
@@ -70,6 +73,7 @@ set(INCLUDE_CORE
7073
# Sources
7174
# Jerry core
7275
file(GLOB SOURCE_CORE_API *.c)
76+
file(GLOB SOURCE_CORE_DEBUGGER debugger/*.c)
7377
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.c)
7478
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.c)
7579
file(GLOB SOURCE_CORE_ECMA_BUILTINS_TYPEDARRAY ecma/builtin-objects/typedarray/*.c)
@@ -96,6 +100,10 @@ set(SOURCE_CORE_FILES
96100
${SOURCE_CORE_PARSER_REGEXP}
97101
${SOURCE_CORE_VM})
98102

103+
if(FEATURE_DEBUGGER)
104+
set(SOURCE_CORE_FILES ${SOURCE_CORE_FILES} ${SOURCE_CORE_DEBUGGER})
105+
endif()
106+
99107
# Jerry port
100108
file(GLOB SOURCE_PORT_FILES "${PORT_DIR}/*.c")
101109

@@ -162,6 +170,11 @@ if(FEATURE_MEM_STATS)
162170
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_STATS)
163171
endif()
164172

173+
# Enable debugger
174+
if(FEATURE_DEBUGGER)
175+
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DEBUGGER)
176+
endif()
177+
165178
# Memory management stress-test mode
166179
if(FEATURE_MEM_STRESS_TEST)
167180
set(DEFINES_JERRY ${DEFINES_JERRY} JMEM_GC_BEFORE_EACH_ALLOC)
@@ -185,6 +198,10 @@ else()
185198
MESSAGE(FATAL_ERROR "Profile file: '${FEATURE_PROFILE}' doesn't exist!")
186199
endif()
187200

201+
if(JERRY_LIBC AND FEATURE_DEBUGGER)
202+
MESSAGE(FATAL_ERROR "This configuration is not supported. Please build against your system libc to enable the JerryScript debugger.")
203+
endif()
204+
188205
# RegExp byte-code dumps
189206
if(FEATURE_REGEXP_DUMP)
190207
set(DEFINES_JERRY ${DEFINES_JERRY} REGEXP_DUMP_BYTE_CODE)

0 commit comments

Comments
 (0)