Skip to content

Commit a79c217

Browse files
knightburtonLaszloLango
authored andcommitted
Add finish debugger command. (#2240)
With this command the engine continue running just after the function in the current stack frame returns. JerryScript-DCO-1.0-Signed-off-by: Imre Kiss [email protected]
1 parent 685af74 commit a79c217

File tree

9 files changed

+117
-18
lines changed

9 files changed

+117
-18
lines changed

jerry-core/debugger/debugger.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* debugger versioning.
3636
*/
3737
JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 27
38-
&& JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT == 18
39-
&& JERRY_DEBUGGER_VERSION == 1,
38+
&& JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT == 19
39+
&& JERRY_DEBUGGER_VERSION == 2,
4040
debugger_version_correlates_to_message_type_count);
4141

4242
/**
@@ -438,6 +438,19 @@ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer to the rece
438438
return true;
439439
}
440440

441+
case JERRY_DEBUGGER_FINISH:
442+
{
443+
JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t);
444+
445+
JERRY_DEBUGGER_SET_FLAGS (JERRY_DEBUGGER_VM_STOP);
446+
447+
/* This will point to the current context's parent (where the function was called)
448+
* and in case of NULL the result will the same as in case of STEP. */
449+
JERRY_CONTEXT (debugger_stop_context) = JERRY_CONTEXT (vm_top_context_p->prev_context_p);
450+
*resume_exec_p = true;
451+
return true;
452+
}
453+
441454
case JERRY_DEBUGGER_GET_BACKTRACE:
442455
{
443456
JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_get_backtrace_t);

jerry-core/debugger/debugger.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* JerryScript debugger protocol version.
2828
*/
29-
#define JERRY_DEBUGGER_VERSION (1)
29+
#define JERRY_DEBUGGER_VERSION (2)
3030

3131
/**
3232
* Frequency of calling jerry_debugger_receive() by the VM.
@@ -178,11 +178,12 @@ typedef enum
178178
JERRY_DEBUGGER_CONTINUE = 12, /**< continue execution */
179179
JERRY_DEBUGGER_STEP = 13, /**< next breakpoint, step into functions */
180180
JERRY_DEBUGGER_NEXT = 14, /**< next breakpoint in the same context */
181+
JERRY_DEBUGGER_FINISH = 15, /**< Continue running just after the function in the current stack frame returns */
181182
/* The following messages are only available in breakpoint
182183
* mode and this mode is kept after the message is processed. */
183-
JERRY_DEBUGGER_GET_BACKTRACE = 15, /**< get backtrace */
184-
JERRY_DEBUGGER_EVAL = 16, /**< first message of evaluating a string */
185-
JERRY_DEBUGGER_EVAL_PART = 17, /**< next message of evaluating a string */
184+
JERRY_DEBUGGER_GET_BACKTRACE = 16, /**< get backtrace */
185+
JERRY_DEBUGGER_EVAL = 17, /**< first message of evaluating a string */
186+
JERRY_DEBUGGER_EVAL_PART = 18, /**< next message of evaluating a string */
186187

187188
JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT, /**< number of different type of input messages */
188189
} jerry_debugger_header_type_t;

jerry-debugger/jerry-client-ws.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
3636
</div>
3737
<script>
3838
// Expected JerryScript debugger protocol version
39-
var JERRY_DEBUGGER_VERSION = 1;
39+
var JERRY_DEBUGGER_VERSION = 2;
4040

4141
// Messages sent by the server to client.
4242
var JERRY_DEBUGGER_CONFIGURATION = 1;
@@ -92,9 +92,10 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
9292
var JERRY_DEBUGGER_CONTINUE = 12;
9393
var JERRY_DEBUGGER_STEP = 13;
9494
var JERRY_DEBUGGER_NEXT = 14;
95-
var JERRY_DEBUGGER_GET_BACKTRACE = 15;
96-
var JERRY_DEBUGGER_EVAL = 16;
97-
var JERRY_DEBUGGER_EVAL_PART = 17;
95+
var JERRY_DEBUGGER_FINISH = 15;
96+
var JERRY_DEBUGGER_GET_BACKTRACE = 16;
97+
var JERRY_DEBUGGER_EVAL = 17;
98+
var JERRY_DEBUGGER_EVAL_PART = 18;
9899

99100
var textBox = document.getElementById("log");
100101
var commandBox = document.getElementById("command");
@@ -1367,6 +1368,7 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
13671368
" continue|c - continue execution\n" +
13681369
" step|s - step-in execution\n" +
13691370
" next|n - execution until the next breakpoint\n" +
1371+
" finish|f - continue running until the current function returns\n" +
13701372
" eval|e - evaluate expression\n" +
13711373
" backtrace|bt <max-depth> - get backtrace\n" +
13721374
" src - print current source code\n" +
@@ -1461,6 +1463,11 @@ <h2>JerryScript HTML (WebSocket) Debugger Client</h2>
14611463
debuggerObj.sendResumeExec(JERRY_DEBUGGER_NEXT);
14621464
break;
14631465

1466+
case "f":
1467+
case "finish":
1468+
debuggerObj.sendResumeExec(JERRY_DEBUGGER_FINISH);
1469+
break;
1470+
14641471
case "e":
14651472
case "eval":
14661473
debuggerObj.sendEval(args[2]);

jerry-debugger/jerry-client-ws.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import time
2929

3030
# Expected debugger protocol version.
31-
JERRY_DEBUGGER_VERSION = 1
31+
JERRY_DEBUGGER_VERSION = 2
3232

3333
# Messages sent by the server to client.
3434
JERRY_DEBUGGER_CONFIGURATION = 1
@@ -85,9 +85,10 @@
8585
JERRY_DEBUGGER_CONTINUE = 12
8686
JERRY_DEBUGGER_STEP = 13
8787
JERRY_DEBUGGER_NEXT = 14
88-
JERRY_DEBUGGER_GET_BACKTRACE = 15
89-
JERRY_DEBUGGER_EVAL = 16
90-
JERRY_DEBUGGER_EVAL_PART = 17
88+
JERRY_DEBUGGER_FINISH = 15
89+
JERRY_DEBUGGER_GET_BACKTRACE = 16
90+
JERRY_DEBUGGER_EVAL = 17
91+
JERRY_DEBUGGER_EVAL_PART = 18
9192

9293
MAX_BUFFER_SIZE = 128
9394
WEBSOCKET_BINARY_FRAME = 2
@@ -286,6 +287,13 @@ def do_next(self, args):
286287

287288
do_n = do_next
288289

290+
def do_finish(self, args):
291+
""" Continue running until the current function returns """
292+
self._exec_command(args, JERRY_DEBUGGER_FINISH)
293+
self.cont = True
294+
295+
do_f = do_finish
296+
289297
def do_list(self, _):
290298
""" Lists the available breakpoints """
291299
if self.debugger.active_breakpoint_list:

tests/debugger/do_finish.cmd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
finish
2+
finish
3+
finish
4+
step
5+
finish
6+
continue

tests/debugger/do_finish.expected

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Connecting to: localhost:5001
2+
Stopped at tests/debugger/do_finish.js:15
3+
(jerry-debugger) finish
4+
out: finish-test
5+
Stopped at tests/debugger/do_finish.js:26
6+
(jerry-debugger) finish
7+
Stopped at tests/debugger/do_finish.js:18 (in foo() at line:17, col:1)
8+
(jerry-debugger) finish
9+
out: foo
10+
out: bar
11+
Stopped at tests/debugger/do_finish.js:42
12+
(jerry-debugger) step
13+
Stopped at tests/debugger/do_finish.js:29 (in dog() at line:28, col:1)
14+
(jerry-debugger) finish
15+
out: *bark*
16+
out: *sit*
17+
out: *bark*
18+
Stopped at tests/debugger/do_finish.js:44
19+
(jerry-debugger) continue
20+
out: END: finish-test

tests/debugger/do_finish.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
print("finish-test");
16+
17+
function foo() {
18+
print("foo");
19+
return bar();
20+
}
21+
22+
function bar() {
23+
return "bar";
24+
}
25+
26+
print(foo());
27+
28+
function dog() {
29+
bark();
30+
sit();
31+
bark();
32+
}
33+
34+
function bark() {
35+
print("*bark*");
36+
}
37+
38+
function sit() {
39+
print("*sit*");
40+
}
41+
42+
dog();
43+
44+
print("END: finish-test");

tests/debugger/do_help.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Stopped at tests/debugger/do_help.js:15
44

55
Documented commands (type help <topic>):
66
========================================
7-
b bt delete e help ms quit source
8-
backtrace c display eval list n s src
9-
break continue dump exception memstats next scroll step
7+
b bt delete e f list n s src
8+
backtrace c display eval finish memstats next scroll step
9+
break continue dump exception help ms quit source
1010

1111
(jerry-debugger) quit

tools/pylint/pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ max-attributes=7
331331
min-public-methods=0
332332

333333
# Maximum number of public methods for a class (see R0904).
334-
max-public-methods=20
334+
max-public-methods=25
335335

336336
# Maximum number of boolean expressions in a if statement
337337
max-bool-expr=5

0 commit comments

Comments
 (0)