Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions jerry-core/debugger/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

uint32_t min_depth;
memcpy (&min_depth, get_backtrace_p->min_depth, sizeof (uint32_t));
uint32_t max_depth;
memcpy (&max_depth, get_backtrace_p->max_depth, sizeof (uint32_t));

Expand All @@ -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_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;
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;
}

if (current_frame >= max_frame_count)
{
if (!jerry_debugger_send (max_message_size))
{
return;
}
current_frame = 0;
}
current_frame = 0;
}

jerry_debugger_frame_t *frame_p = backtrace_p->frames + 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));
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));
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--;
frame_ctx_p = frame_ctx_p->prev_context_p;
current_frame++;
}
}

size_t message_size = current_frame * sizeof (jerry_debugger_frame_t);
Expand Down
1 change: 1 addition & 0 deletions jerry-core/debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ typedef struct
typedef struct
{
uint8_t type; /**< type of the message */
uint8_t min_depth[sizeof (uint32_t)]; /**< minimum depth*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use uint16_t for both min_depth and max_depth? @zherczeg, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently only uint8, cpointer, and uint32 types are used by the protocol. Adding new types would require adding new encoders/decoders for clients. This is certainly possible, but for this it does not seem worth the effort.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the explanation.

uint8_t max_depth[sizeof (uint32_t)]; /**< maximum depth (0 - unlimited) */
} jerry_debugger_receive_get_backtrace_t;

Expand Down
34 changes: 26 additions & 8 deletions jerry-debugger/jerry-client-ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ def __repr__(self):


class DebuggerPrompt(Cmd):

# pylint: disable=too-many-instance-attributes,too-many-arguments
def __init__(self, debugger):
Cmd.__init__(self)
self.debugger = debugger
self.stop = False
self.quit = False
self.cont = True
self.min_depth = 0
self.non_interactive = False
self.client_sources = []

Expand Down Expand Up @@ -348,22 +349,36 @@ def do_delete(self, args):
def do_backtrace(self, args):
""" Get backtrace data from debugger """
max_depth = 0
self.min_depth = 0

if args:
args = args.split(" ")
try:
max_depth = int(args)
if max_depth <= 0:
print("Error: Positive integer number expected")
return
if len(args) == 2:
self.min_depth = int(args[0])
max_depth = int(args[1])
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:
print("Error: Positive integer number expected, %s" % (val_errno))
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_FIN_BIT + 1 + 4,
WEBSOCKET_FIN_BIT + 1 + 4 + 4,
0,
JERRY_DEBUGGER_GET_BACKTRACE,
self.min_depth,
max_depth)
self.debugger.send_message(message)
self.stop = True
Expand Down Expand Up @@ -1193,7 +1208,10 @@ def main():
exception_string += data[3:]

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:

Expand Down
6 changes: 6 additions & 0 deletions tests/debugger/do_backtrace.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ next
step
next
s
bt 1 2
bt
bt 2
n
n
s
backtrace
bt 4 4
bt 600 919
bt 3 500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if min greater than the max? Can we test it?

bt 4 3
c
11 changes: 11 additions & 0 deletions tests/debugger/do_backtrace.expected
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ out: function test
Stopped at tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
(jerry-debugger) s
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
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 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
out: function foo
Stopped at tests/debugger/do_backtrace.js:24 (in foo() at line:21, col:1)
Expand All @@ -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 2: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1)
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
out: function f4