diff options
author | Daniella Barsony <bella@inf.u-szeged.hu> | 2018-08-03 11:30:13 +0200 |
---|---|---|
committer | Robert Sipka <rsipka.uszeged@partner.samsung.com> | 2018-08-03 11:30:13 +0200 |
commit | 64051b5bd857985e67b4922ecc654f26144c5520 (patch) | |
tree | 71cd62bd71a35d1bdffa6c50a72bb88aaaa6b2e6 | |
parent | 87897849f6879df10e8ad68a41bf8cf507edf710 (diff) |
Add total frame counter to backtrace in debugger (#2428)
This was needed for the VScode extension so we know in total howmany frames we have in the backtrace.
JerryScript-DCO-1.0-Signed-off-by: Daniella Barsony bella@inf.u-szeged.hu
-rw-r--r-- | jerry-core/debugger/debugger.c | 21 | ||||
-rw-r--r-- | jerry-core/debugger/debugger.h | 27 | ||||
-rwxr-xr-x | jerry-debugger/jerry_client_ws.py | 64 | ||||
-rw-r--r-- | tests/debugger/do_backtrace.cmd | 4 | ||||
-rw-r--r-- | tests/debugger/do_backtrace.expected | 17 | ||||
-rw-r--r-- | tools/pylint/pylintrc | 2 |
6 files changed, 104 insertions, 31 deletions
diff --git a/jerry-core/debugger/debugger.c b/jerry-core/debugger/debugger.c index 9dff4798..7a1a5920 100644 --- a/jerry-core/debugger/debugger.c +++ b/jerry-core/debugger/debugger.c @@ -37,9 +37,9 @@ typedef struct * The number of message types in the debugger should reflect the * debugger versioning. */ -JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 27 +JERRY_STATIC_ASSERT (JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT == 28 && JERRY_DEBUGGER_MESSAGES_IN_MAX_COUNT == 19 - && JERRY_DEBUGGER_VERSION == 4, + && JERRY_DEBUGGER_VERSION == 5, debugger_version_correlates_to_message_type_count); /** @@ -120,6 +120,23 @@ jerry_debugger_send_backtrace (const uint8_t *recv_buffer_p) /**< pointer to the max_depth = UINT32_MAX; } + if (get_backtrace_p->get_total_frame_count != 0) + { + JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_backtrace_total_t, backtrace_total_p); + backtrace_total_p->type = JERRY_DEBUGGER_BACKTRACE_TOTAL; + + vm_frame_ctx_t *iter_frame_ctx_p = JERRY_CONTEXT (vm_top_context_p); + uint32_t frame_count = 0; + while (iter_frame_ctx_p != NULL) + { + frame_count++; + iter_frame_ctx_p = iter_frame_ctx_p->prev_context_p; + } + memcpy (backtrace_total_p->frame_count, &frame_count, sizeof (frame_count)); + + jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + sizeof (frame_count)); + } + JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_backtrace_t, backtrace_p); backtrace_p->type = JERRY_DEBUGGER_BACKTRACE; diff --git a/jerry-core/debugger/debugger.h b/jerry-core/debugger/debugger.h index 0f40735c..58c051c6 100644 --- a/jerry-core/debugger/debugger.h +++ b/jerry-core/debugger/debugger.h @@ -26,7 +26,7 @@ /** * JerryScript debugger protocol version. */ -#define JERRY_DEBUGGER_VERSION (4) +#define JERRY_DEBUGGER_VERSION (5) /** * Frequency of calling jerry_debugger_receive() by the VM. @@ -149,13 +149,14 @@ typedef enum JERRY_DEBUGGER_EXCEPTION_HIT = 17, /**< notify exception hit */ JERRY_DEBUGGER_EXCEPTION_STR = 18, /**< exception string fragment */ JERRY_DEBUGGER_EXCEPTION_STR_END = 19, /**< exception string last fragment */ - JERRY_DEBUGGER_BACKTRACE = 20, /**< backtrace data */ - JERRY_DEBUGGER_BACKTRACE_END = 21, /**< last backtrace data */ - JERRY_DEBUGGER_EVAL_RESULT = 22, /**< eval result */ - JERRY_DEBUGGER_EVAL_RESULT_END = 23, /**< last part of eval result */ - JERRY_DEBUGGER_WAIT_FOR_SOURCE = 24, /**< engine waiting for source code */ - JERRY_DEBUGGER_OUTPUT_RESULT = 25, /**< output sent by the program to the debugger */ - JERRY_DEBUGGER_OUTPUT_RESULT_END = 26, /**< last output result data */ + JERRY_DEBUGGER_BACKTRACE_TOTAL = 20, /**< number of total frames */ + JERRY_DEBUGGER_BACKTRACE = 21, /**< backtrace data */ + JERRY_DEBUGGER_BACKTRACE_END = 22, /**< last backtrace data */ + JERRY_DEBUGGER_EVAL_RESULT = 23, /**< eval result */ + JERRY_DEBUGGER_EVAL_RESULT_END = 24, /**< last part of eval result */ + JERRY_DEBUGGER_WAIT_FOR_SOURCE = 25, /**< engine waiting for source code */ + JERRY_DEBUGGER_OUTPUT_RESULT = 26, /**< output sent by the program to the debugger */ + JERRY_DEBUGGER_OUTPUT_RESULT_END = 27, /**< last output result data */ JERRY_DEBUGGER_MESSAGES_OUT_MAX_COUNT, /**< number of different type of output messages by the debugger */ @@ -357,6 +358,15 @@ typedef struct } jerry_debugger_send_backtrace_t; /** + * Outgoing message: number of total frames in backtrace. + */ +typedef struct +{ + uint8_t type; /**< type of the message */ + uint8_t frame_count[sizeof (uint32_t)]; /**< total number of frames*/ +} jerry_debugger_send_backtrace_total_t; + +/** * Incoming message: set behaviour when exception occures. */ typedef struct @@ -382,6 +392,7 @@ typedef struct 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 get_total_frame_count; /**< non-zero: if total frame count is also requested */ } jerry_debugger_receive_get_backtrace_t; /** diff --git a/jerry-debugger/jerry_client_ws.py b/jerry-debugger/jerry_client_ws.py index 9a448dcb..55f42b3c 100755 --- a/jerry-debugger/jerry_client_ws.py +++ b/jerry-debugger/jerry_client_ws.py @@ -24,7 +24,7 @@ import struct import sys # Expected debugger protocol version. -JERRY_DEBUGGER_VERSION = 4 +JERRY_DEBUGGER_VERSION = 5 JERRY_DEBUGGER_DATA_END = '\3' # Messages sent by the server to client. @@ -47,13 +47,14 @@ JERRY_DEBUGGER_BREAKPOINT_HIT = 16 JERRY_DEBUGGER_EXCEPTION_HIT = 17 JERRY_DEBUGGER_EXCEPTION_STR = 18 JERRY_DEBUGGER_EXCEPTION_STR_END = 19 -JERRY_DEBUGGER_BACKTRACE = 20 -JERRY_DEBUGGER_BACKTRACE_END = 21 -JERRY_DEBUGGER_EVAL_RESULT = 22 -JERRY_DEBUGGER_EVAL_RESULT_END = 23 -JERRY_DEBUGGER_WAIT_FOR_SOURCE = 24 -JERRY_DEBUGGER_OUTPUT_RESULT = 25 -JERRY_DEBUGGER_OUTPUT_RESULT_END = 26 +JERRY_DEBUGGER_BACKTRACE_TOTAL = 20 +JERRY_DEBUGGER_BACKTRACE = 21 +JERRY_DEBUGGER_BACKTRACE_END = 22 +JERRY_DEBUGGER_EVAL_RESULT = 23 +JERRY_DEBUGGER_EVAL_RESULT_END = 24 +JERRY_DEBUGGER_WAIT_FOR_SOURCE = 25 +JERRY_DEBUGGER_OUTPUT_RESULT = 26 +JERRY_DEBUGGER_OUTPUT_RESULT_END = 27 # Subtypes of eval JERRY_DEBUGGER_EVAL_EVAL = "\0" @@ -276,6 +277,8 @@ class JerryDebugger(object): self.breakpoint_info = '' self.smessage = '' self.min_depth = 0 + self.max_depth = 0 + self.get_total = 0 self.send_message(b"GET /jerry-debugger HTTP/1.1\r\n" + b"Upgrade: websocket\r\n" + @@ -451,36 +454,41 @@ class JerryDebugger(object): return DisplayData("delete", result) def backtrace(self, args): - max_depth = 0 self.min_depth = 0 + self.max_depth = 0 + self.get_total = 0 if args: args = args.split(" ") try: + if "t" in args: + self.get_total = 1 + args = args[:-1] if len(args) == 2: self.min_depth = int(args[0]) - max_depth = int(args[1]) - if max_depth <= 0 or self.min_depth < 0: + self.max_depth = int(args[1]) + if self.max_depth <= 0 or self.min_depth < 0: return DisplayData("backtrace", "Error: Positive integer number expected") - if self.min_depth > max_depth: + if self.min_depth > self.max_depth: return DisplayData("backtrace", "Error: Start depth needs to be lower than or equal to max" \ " depth") - else: - max_depth = int(args[0]) - if max_depth <= 0: + elif len(args) == 1: + self.max_depth = int(args[0]) + if self.max_depth <= 0: return DisplayData("backtrace", "Error: Positive integer number expected") except ValueError as val_errno: return DisplayData("backtrace", "Error: Positive integer number expected, %s" % (val_errno)) - message = struct.pack(self.byte_order + "BBIB" + self.idx_format + self.idx_format, + message = struct.pack(self.byte_order + "BBIB" + self.idx_format + self.idx_format + "B", WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT, - WEBSOCKET_FIN_BIT + 1 + 4 + 4, + WEBSOCKET_FIN_BIT + 1 + 4 + 4 + 1, 0, JERRY_DEBUGGER_GET_BACKTRACE, self.min_depth, - max_depth) + self.max_depth, + self.get_total) self.send_message(message) def eval(self, code): @@ -776,16 +784,21 @@ class JerryDebugger(object): elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR_END: 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, + JERRY_DEBUGGER_BACKTRACE_TOTAL]: if self.min_depth != 0: frame_index = self.min_depth else: frame_index = 0 + total_frames = 0 while True: + if buffer_type == JERRY_DEBUGGER_BACKTRACE_TOTAL: + total_frames = struct.unpack(self.byte_order + self.idx_format, data[3:7])[0] buffer_pos = 3 - while buffer_size > 0: + while buffer_size > 4: breakpoint_data = struct.unpack(self.byte_order + self.cp_format + self.idx_format, data[buffer_pos: buffer_pos + self.cp_size + 4]) @@ -800,6 +813,17 @@ class JerryDebugger(object): result += '\n' if buffer_type == JERRY_DEBUGGER_BACKTRACE_END: + if self.get_total == 1: + if self.max_depth > total_frames: + self.max_depth = total_frames + if self.max_depth == 0: + result += ("\nTotal Frames: %d" % total_frames) + elif self.min_depth != 0 and self.max_depth != 0 and \ + (self.max_depth - self.min_depth) > 0: + result += ("\nGetting %d frames. There are %d in total." % + ((self.max_depth - self.min_depth), total_frames)) + elif self.min_depth == 0 and self.max_depth != 0: + result += ("\nGetting the first %d frames out of %d." % (self.max_depth, total_frames)) break data = self.get_message(True) diff --git a/tests/debugger/do_backtrace.cmd b/tests/debugger/do_backtrace.cmd index bcb56c74..f81cf5f4 100644 --- a/tests/debugger/do_backtrace.cmd +++ b/tests/debugger/do_backtrace.cmd @@ -4,9 +4,12 @@ next step next s +bt 1 2 t bt 1 2 +bt 0 3 t bt bt 2 +bt 2 t n n s @@ -14,5 +17,6 @@ backtrace bt 4 4 bt 600 919 bt 3 500 +bt 42 bt 4 3 c diff --git a/tests/debugger/do_backtrace.expected b/tests/debugger/do_backtrace.expected index 679fcb8d..6cf234c2 100644 --- a/tests/debugger/do_backtrace.expected +++ b/tests/debugger/do_backtrace.expected @@ -14,8 +14,16 @@ 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 t +Frame 1: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1) +Getting 1 frames. There are 3 in total. (jerry-debugger) bt 1 2 Frame 1: tests/debugger/do_backtrace.js:33 (in test() at line:30, col:1) +(jerry-debugger) bt 0 3 t +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 +Getting the first 3 frames out of 3. (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) @@ -23,6 +31,10 @@ 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) bt 2 t +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) +Getting the first 2 frames out of 3. (jerry-debugger) n out: function foo Stopped at tests/debugger/do_backtrace.js:24 (in foo() at line:21, col:1) @@ -39,6 +51,11 @@ Frame 3: tests/debugger/do_backtrace.js:40 (jerry-debugger) bt 600 919 (jerry-debugger) bt 3 500 Frame 3: tests/debugger/do_backtrace.js:40 +(jerry-debugger) bt 42 +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 3 Error: Start depth needs to be lower than or equal to max depth (jerry-debugger) c diff --git a/tools/pylint/pylintrc b/tools/pylint/pylintrc index 6cb2afbc..e07b6b80 100644 --- a/tools/pylint/pylintrc +++ b/tools/pylint/pylintrc @@ -275,7 +275,7 @@ docstring-min-length=-1 [ELIF] # Maximum number of nested blocks for function / method body -max-nested-blocks=5 +max-nested-blocks=7 [LOGGING] |