Add start to backtrace for debugger (#2407)
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
This commit is contained in:
committed by
Zoltan Herczeg
parent
04dcefe087
commit
62cdb3965f
@@ -78,6 +78,8 @@ jerry_debugger_send_backtrace (uint8_t *recv_buffer_p) /**< pointer to the recei
|
|||||||
{
|
{
|
||||||
JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_get_backtrace_t, get_backtrace_p);
|
JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_get_backtrace_t, get_backtrace_p);
|
||||||
|
|
||||||
|
uint32_t min_depth;
|
||||||
|
memcpy (&min_depth, get_backtrace_p->min_depth, sizeof (uint32_t));
|
||||||
uint32_t max_depth;
|
uint32_t max_depth;
|
||||||
memcpy (&max_depth, get_backtrace_p->max_depth, sizeof (uint32_t));
|
memcpy (&max_depth, get_backtrace_p->max_depth, sizeof (uint32_t));
|
||||||
|
|
||||||
@@ -96,35 +98,45 @@ jerry_debugger_send_backtrace (uint8_t *recv_buffer_p) /**< pointer to the recei
|
|||||||
const size_t max_frame_count = JERRY_DEBUGGER_SEND_MAX (jerry_debugger_frame_t);
|
const size_t max_frame_count = JERRY_DEBUGGER_SEND_MAX (jerry_debugger_frame_t);
|
||||||
const size_t max_message_size = JERRY_DEBUGGER_SEND_SIZE (max_frame_count, jerry_debugger_frame_t);
|
const size_t max_message_size = JERRY_DEBUGGER_SEND_SIZE (max_frame_count, jerry_debugger_frame_t);
|
||||||
|
|
||||||
while (frame_ctx_p != NULL && max_depth > 0)
|
if (min_depth <= max_depth)
|
||||||
{
|
{
|
||||||
if (frame_ctx_p->bytecode_header_p->status_flags & CBC_CODE_FLAGS_DEBUGGER_IGNORE)
|
uint32_t min_depth_offset = 0;
|
||||||
|
|
||||||
|
while (frame_ctx_p != NULL && min_depth_offset < min_depth)
|
||||||
{
|
{
|
||||||
frame_ctx_p = frame_ctx_p->prev_context_p;
|
frame_ctx_p = frame_ctx_p->prev_context_p;
|
||||||
continue;
|
min_depth_offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_frame >= max_frame_count)
|
while (frame_ctx_p != NULL && min_depth_offset++ < max_depth)
|
||||||
{
|
{
|
||||||
if (!jerry_debugger_send (max_message_size))
|
if (frame_ctx_p->bytecode_header_p->status_flags & CBC_CODE_FLAGS_DEBUGGER_IGNORE)
|
||||||
{
|
{
|
||||||
return;
|
frame_ctx_p = frame_ctx_p->prev_context_p;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
current_frame = 0;
|
|
||||||
|
if (current_frame >= max_frame_count)
|
||||||
|
{
|
||||||
|
if (!jerry_debugger_send (max_message_size))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
current_frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
jerry_debugger_frame_t *frame_p = backtrace_p->frames + current_frame;
|
||||||
|
|
||||||
|
jmem_cpointer_t byte_code_cp;
|
||||||
|
JMEM_CP_SET_NON_NULL_POINTER (byte_code_cp, frame_ctx_p->bytecode_header_p);
|
||||||
|
memcpy (frame_p->byte_code_cp, &byte_code_cp, sizeof (jmem_cpointer_t));
|
||||||
|
|
||||||
|
uint32_t offset = (uint32_t) (frame_ctx_p->byte_code_p - (uint8_t *) frame_ctx_p->bytecode_header_p);
|
||||||
|
memcpy (frame_p->offset, &offset, sizeof (uint32_t));
|
||||||
|
|
||||||
|
frame_ctx_p = frame_ctx_p->prev_context_p;
|
||||||
|
current_frame++;
|
||||||
}
|
}
|
||||||
|
|
||||||
jerry_debugger_frame_t *frame_p = backtrace_p->frames + current_frame;
|
|
||||||
|
|
||||||
jmem_cpointer_t byte_code_cp;
|
|
||||||
JMEM_CP_SET_NON_NULL_POINTER (byte_code_cp, frame_ctx_p->bytecode_header_p);
|
|
||||||
memcpy (frame_p->byte_code_cp, &byte_code_cp, sizeof (jmem_cpointer_t));
|
|
||||||
|
|
||||||
uint32_t offset = (uint32_t) (frame_ctx_p->byte_code_p - (uint8_t *) frame_ctx_p->bytecode_header_p);
|
|
||||||
memcpy (frame_p->offset, &offset, sizeof (uint32_t));
|
|
||||||
|
|
||||||
frame_ctx_p = frame_ctx_p->prev_context_p;
|
|
||||||
current_frame++;
|
|
||||||
max_depth--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t message_size = current_frame * sizeof (jerry_debugger_frame_t);
|
size_t message_size = current_frame * sizeof (jerry_debugger_frame_t);
|
||||||
|
|||||||
@@ -376,6 +376,7 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t type; /**< type of the message */
|
uint8_t type; /**< type of the message */
|
||||||
|
uint8_t min_depth[sizeof (uint32_t)]; /**< minimum depth*/
|
||||||
uint8_t max_depth[sizeof (uint32_t)]; /**< maximum depth (0 - unlimited) */
|
uint8_t max_depth[sizeof (uint32_t)]; /**< maximum depth (0 - unlimited) */
|
||||||
} jerry_debugger_receive_get_backtrace_t;
|
} jerry_debugger_receive_get_backtrace_t;
|
||||||
|
|
||||||
|
|||||||
@@ -200,13 +200,14 @@ class JerryFunction(object):
|
|||||||
|
|
||||||
|
|
||||||
class DebuggerPrompt(Cmd):
|
class DebuggerPrompt(Cmd):
|
||||||
|
# pylint: disable=too-many-instance-attributes,too-many-arguments
|
||||||
def __init__(self, debugger):
|
def __init__(self, debugger):
|
||||||
Cmd.__init__(self)
|
Cmd.__init__(self)
|
||||||
self.debugger = debugger
|
self.debugger = debugger
|
||||||
self.stop = False
|
self.stop = False
|
||||||
self.quit = False
|
self.quit = False
|
||||||
self.cont = True
|
self.cont = True
|
||||||
|
self.min_depth = 0
|
||||||
self.non_interactive = False
|
self.non_interactive = False
|
||||||
self.client_sources = []
|
self.client_sources = []
|
||||||
|
|
||||||
@@ -348,22 +349,36 @@ class DebuggerPrompt(Cmd):
|
|||||||
def do_backtrace(self, args):
|
def do_backtrace(self, args):
|
||||||
""" Get backtrace data from debugger """
|
""" Get backtrace data from debugger """
|
||||||
max_depth = 0
|
max_depth = 0
|
||||||
|
self.min_depth = 0
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
|
args = args.split(" ")
|
||||||
try:
|
try:
|
||||||
max_depth = int(args)
|
if len(args) == 2:
|
||||||
if max_depth <= 0:
|
self.min_depth = int(args[0])
|
||||||
print("Error: Positive integer number expected")
|
max_depth = int(args[1])
|
||||||
return
|
if max_depth <= 0 or self.min_depth < 0:
|
||||||
|
print("Error: Positive integer number expected")
|
||||||
|
return
|
||||||
|
if self.min_depth > max_depth:
|
||||||
|
print("Error: Start depth needs to be lower than or equal to max depth")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
max_depth = int(args[0])
|
||||||
|
if max_depth <= 0:
|
||||||
|
print("Error: Positive integer number expected")
|
||||||
|
return
|
||||||
|
|
||||||
except ValueError as val_errno:
|
except ValueError as val_errno:
|
||||||
print("Error: Positive integer number expected, %s" % (val_errno))
|
print("Error: Positive integer number expected, %s" % (val_errno))
|
||||||
return
|
return
|
||||||
|
|
||||||
message = struct.pack(self.debugger.byte_order + "BBIB" + self.debugger.idx_format,
|
message = struct.pack(self.debugger.byte_order + "BBIB" + self.debugger.idx_format + self.debugger.idx_format,
|
||||||
WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT,
|
WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT,
|
||||||
WEBSOCKET_FIN_BIT + 1 + 4,
|
WEBSOCKET_FIN_BIT + 1 + 4 + 4,
|
||||||
0,
|
0,
|
||||||
JERRY_DEBUGGER_GET_BACKTRACE,
|
JERRY_DEBUGGER_GET_BACKTRACE,
|
||||||
|
self.min_depth,
|
||||||
max_depth)
|
max_depth)
|
||||||
self.debugger.send_message(message)
|
self.debugger.send_message(message)
|
||||||
self.stop = True
|
self.stop = True
|
||||||
@@ -1199,7 +1214,10 @@ def main():
|
|||||||
exception_string += data[3:]
|
exception_string += data[3:]
|
||||||
|
|
||||||
elif buffer_type in [JERRY_DEBUGGER_BACKTRACE, JERRY_DEBUGGER_BACKTRACE_END]:
|
elif buffer_type in [JERRY_DEBUGGER_BACKTRACE, JERRY_DEBUGGER_BACKTRACE_END]:
|
||||||
frame_index = 0
|
if prompt.min_depth != 0:
|
||||||
|
frame_index = prompt.min_depth
|
||||||
|
else:
|
||||||
|
frame_index = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,15 @@ next
|
|||||||
step
|
step
|
||||||
next
|
next
|
||||||
s
|
s
|
||||||
|
bt 1 2
|
||||||
bt
|
bt
|
||||||
|
bt 2
|
||||||
n
|
n
|
||||||
n
|
n
|
||||||
s
|
s
|
||||||
backtrace
|
backtrace
|
||||||
|
bt 4 4
|
||||||
|
bt 600 919
|
||||||
|
bt 3 500
|
||||||
|
bt 4 3
|
||||||
c
|
c
|
||||||
|
|||||||
@@ -14,10 +14,15 @@ out: function test
|
|||||||
Stopped at tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
Stopped at tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
||||||
(jerry-debugger) s
|
(jerry-debugger) s
|
||||||
Stopped at tests/debugger/do_backtrace.js:23 (in foo() at line:21, col:1)
|
Stopped at tests/debugger/do_backtrace.js:23 (in foo() at line:21, col:1)
|
||||||
|
(jerry-debugger) bt 1 2
|
||||||
|
Frame 1: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
||||||
(jerry-debugger) bt
|
(jerry-debugger) bt
|
||||||
Frame 0: tests/debugger/do_backtrace.js:23 (in foo() at line:21, col:1)
|
Frame 0: tests/debugger/do_backtrace.js:23 (in foo() at line:21, col:1)
|
||||||
Frame 1: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
Frame 1: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
||||||
Frame 2: tests/debugger/do_backtrace.js:40
|
Frame 2: tests/debugger/do_backtrace.js:40
|
||||||
|
(jerry-debugger) bt 2
|
||||||
|
Frame 0: tests/debugger/do_backtrace.js:23 (in foo() at line:21, col:1)
|
||||||
|
Frame 1: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
||||||
(jerry-debugger) n
|
(jerry-debugger) n
|
||||||
out: function foo
|
out: function foo
|
||||||
Stopped at tests/debugger/do_backtrace.js:24 (in foo() at line:21, col:1)
|
Stopped at tests/debugger/do_backtrace.js:24 (in foo() at line:21, col:1)
|
||||||
@@ -30,5 +35,11 @@ Frame 0: tests/debugger/do_backtrace.js:18 (in f4() at line:17, col:1)
|
|||||||
Frame 1: tests/debugger/do_backtrace.js:25 (in foo() at line:21, col:1)
|
Frame 1: tests/debugger/do_backtrace.js:25 (in foo() at line:21, col:1)
|
||||||
Frame 2: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
Frame 2: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
|
||||||
Frame 3: tests/debugger/do_backtrace.js:40
|
Frame 3: tests/debugger/do_backtrace.js:40
|
||||||
|
(jerry-debugger) bt 4 4
|
||||||
|
(jerry-debugger) bt 600 919
|
||||||
|
(jerry-debugger) bt 3 500
|
||||||
|
Frame 3: tests/debugger/do_backtrace.js:40
|
||||||
|
(jerry-debugger) bt 4 3
|
||||||
|
Error: Start depth needs to be lower than or equal to max depth
|
||||||
(jerry-debugger) c
|
(jerry-debugger) c
|
||||||
out: function f4
|
out: function f4
|
||||||
|
|||||||
Reference in New Issue
Block a user