diff --git a/jerry-debugger/jerry-client-ws.py b/jerry-debugger/jerry-client-ws.py index cbf51bc41..96ca5a4a1 100755 --- a/jerry-debugger/jerry-client-ws.py +++ b/jerry-debugger/jerry-client-ws.py @@ -159,12 +159,6 @@ class DebuggerPrompt(Cmd): def postcmd(self, stop, line): return self.stop - def insert_breakpoint(self, args): - if args == "": - print("Error: Breakpoint index expected") - else: - set_breakpoint(self.debugger, args) - def disable_args(self, args): if args: print("Error: No argument expected") @@ -180,11 +174,21 @@ class DebuggerPrompt(Cmd): self.quit = True def do_break(self, args): - """ Insert breakpoints on the given lines """ - self.insert_breakpoint(args) + """ Insert breakpoints on the given lines or functions """ + if args == "": + print("Error: Breakpoint index expected") + else: + set_breakpoint(self.debugger, False, args) do_b = do_break + def do_fbreak(self, args): + """ Insert breakpoints on the given lines or functions, if not found add the pending list """ + if args == "": + print("Error: Breakpoint index expected") + else: + set_breakpoint(self.debugger, True, args) + def exec_command(self, args, command_id): self.stop = True if args != "": @@ -217,8 +221,10 @@ class DebuggerPrompt(Cmd): do_n = do_next def do_list(self, args): - """ Lists the available breakpoints """ - if self.disable_args(args): + """ Lists the available breakpoints, use 'pending' to list all the available pending breakpoints """ + if args == "pending": + for index, breakpoint in enumerate(self.debugger.pending_breakpoint_list): + print("%d: %s" % (index, breakpoint)) return for breakpoint in self.debugger.active_breakpoint_list.values(): @@ -250,6 +256,28 @@ class DebuggerPrompt(Cmd): else: print("Error: Breakpoint %d not found" % (breakpoint_index)) + def do_pendingdel(self, args): + """ Delete the given pending breakpoints from the list """ + if not args: + print("Error: Pending breakpoint index expected") + return + + else: + try: + breakpoint_index = int(args) + except ValueError as val_errno: + print("Error: Integer number expectes, %s" % (val_errno)) + return + + if breakpoint_index <= len(self.debugger.pending_breakpoint_list): + try: + del self.debugger.pending_breakpoint_list[breakpoint_index] + except IndexError as index_errno: + print("Error: Index not found, %s" % (index_errno)) + return + else: + print("Error: Pending breakpoint %d not found" % (breakpoint_index)) + def exec_backtrace(self, args): max_depth = 0 @@ -408,6 +436,7 @@ class JerryDebugger(object): self.last_breakpoint_hit = None self.next_breakpoint_index = 0 self.active_breakpoint_list = {} + self.pending_breakpoint_list = [] self.line_list = Multimap() self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.client_socket.connect((self.host, self.port)) @@ -678,6 +707,17 @@ def parse_source(debugger, data): for line, breakpoint in function.lines.items(): debugger.line_list.insert(line, breakpoint) + # Try to set the pending breakpoints + if len(debugger.pending_breakpoint_list) != 0: + logging.debug("Pending breakpoints list: %s", debugger.pending_breakpoint_list) + + for breakpoint in debugger.pending_breakpoint_list: + if isinstance(breakpoint, int): + breakpoint = source_code_name + ":" + str(breakpoint) + set_breakpoint(debugger, False, breakpoint) + else: + logging.debug("No pending breakpoints") + def release_function(debugger, data): byte_code_cp = struct.unpack(debugger.byte_order + debugger.cp_format, @@ -708,7 +748,7 @@ def enable_breakpoint(debugger, breakpoint): print ("Breakpoint %d at %s" % (breakpoint.active_index, breakpoint)) -def set_breakpoint(debugger, string): +def set_breakpoint(debugger, pending, string): line = re.match("(.*):(\\d+)$", string) found = False @@ -733,7 +773,13 @@ def set_breakpoint(debugger, string): if not found: print("Breakpoint not found") - return + if pending: + if line: + debugger.pending_breakpoint_list.append(line) + else: + debugger.pending_breakpoint_list.append(string) + print ("Pending breakpoint added") + return def get_breakpoint(debugger, breakpoint_data): diff --git a/tests/debugger/do_help.expected b/tests/debugger/do_help.expected index c5baf1f0e..340a79005 100644 --- a/tests/debugger/do_help.expected +++ b/tests/debugger/do_help.expected @@ -4,7 +4,8 @@ Stopped at tests/debugger/do_help.js:15 Documented commands (type help ): ======================================== -b break c delete e exception list next s step -backtrace bt continue dump eval help n quit src +b bt delete eval help next s +backtrace c dump exception list pendingdel src +break continue e fbreak n quit step (jerry-debugger) quit diff --git a/tests/debugger/do_pending_breakpoints.cmd b/tests/debugger/do_pending_breakpoints.cmd new file mode 100644 index 000000000..56f8f5e71 --- /dev/null +++ b/tests/debugger/do_pending_breakpoints.cmd @@ -0,0 +1,6 @@ +fbreak f +list pending +n +n +c +c diff --git a/tests/debugger/do_pending_breakpoints.expected b/tests/debugger/do_pending_breakpoints.expected new file mode 100644 index 000000000..a8688502a --- /dev/null +++ b/tests/debugger/do_pending_breakpoints.expected @@ -0,0 +1,16 @@ +Connecting to: localhost:5001 +Stopped at tests/debugger/do_pending_breakpoints.js:15 +(jerry-debugger) fbreak f +Breakpoint not found +Pending breakpoint added +(jerry-debugger) list pending +0: f +(jerry-debugger) n +Stopped at tests/debugger/do_pending_breakpoints.js:17 +(jerry-debugger) n +Breakpoint 1 at :1 (in f() at line:1, col:1) +Stopped at tests/debugger/do_pending_breakpoints.js:19 +(jerry-debugger) c +Stopped at breakpoint:1 :1 (in f() at line:1, col:1) +(jerry-debugger) c +Connection closed. diff --git a/tests/debugger/do_pending_breakpoints.js b/tests/debugger/do_pending_breakpoints.js new file mode 100644 index 000000000..a7062166a --- /dev/null +++ b/tests/debugger/do_pending_breakpoints.js @@ -0,0 +1,21 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +print("pending-breakpoints"); + +eval("function f(){ return 5 }"); + +var bird = "colibri"; +f(); +var a = 234; diff --git a/tests/debugger/do_pending_list.cmd b/tests/debugger/do_pending_list.cmd new file mode 100644 index 000000000..a255d22da --- /dev/null +++ b/tests/debugger/do_pending_list.cmd @@ -0,0 +1,6 @@ +fbreak do_pending_breakpoints.js:50 +fbreak do_pending_breakpoints.js:235532 +fbreak do_pending_breakpoints.js:2145 +n +list pending +c diff --git a/tests/debugger/do_pending_list.expected b/tests/debugger/do_pending_list.expected new file mode 100644 index 000000000..93e0db841 --- /dev/null +++ b/tests/debugger/do_pending_list.expected @@ -0,0 +1,18 @@ +Connecting to: localhost:5001 +Stopped at tests/debugger/do_pending_list.js:15 +(jerry-debugger) fbreak do_pending_breakpoints.js:50 +Breakpoint not found +Pending breakpoint added +(jerry-debugger) fbreak do_pending_breakpoints.js:235532 +Breakpoint not found +Pending breakpoint added +(jerry-debugger) fbreak do_pending_breakpoints.js:2145 +Breakpoint not found +Pending breakpoint added +(jerry-debugger) n +Stopped at tests/debugger/do_pending_list.js:17 +(jerry-debugger) list pending +0: 50 +1: 235532 +2: 2145 +(jerry-debugger) c diff --git a/tests/debugger/do_pending_list.js b/tests/debugger/do_pending_list.js new file mode 100644 index 000000000..82418db0f --- /dev/null +++ b/tests/debugger/do_pending_list.js @@ -0,0 +1,20 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +print("pending breakpoints list"); + +var x = 10; +var y = 10; +var pi = 3.14; +var z = x + y;