Skip to content

Commit 8fbf7c2

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 77ab2c7 commit 8fbf7c2

23 files changed

+3823
-5
lines changed

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*: 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, /**< */
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 the same as [jerry_parse](#jerry_parse), except a filename parameter is added.
454490

455491
## jerry_run
456492

docs/07.DEBUGGER.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 has not been
21+
supported by jerry-libc yet 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 to reduce
31+
memory consumption. The client is expected to be run on a system
32+
with much more resources and it should be capable of storing
33+
this information instead of JerryScript. Hence debug information
34+
is discarded after it is transmitted to the client.
35+
36+
The following argument makes JerryScript to wait for a client
37+
connection:
38+
39+
`--start-debug-server`
40+
41+
It is also recommended to increase the log-level to see
42+
the *Waiting for client connection* message:
43+
44+
`--log-level 2`
45+
46+
The HTML client can connect the IP address of the server by
47+
the `connect IP-address` command. The IP address can be
48+
localhost if the server and client run on the same machine.
49+
50+
After the connection is established breakpoints can be inserted
51+
and the execution can be controlled by the debugger. All available
52+
commands can be queried by `help`.

jerry-core/CMakeLists.txt

Lines changed: 13 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 debugger option for JerryScript?")
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)

0 commit comments

Comments
 (0)