Add pending breakpoints feature to python debugger client (#1810)

- Support to add pending breakpoints
 - Add fbreak command for the prompt
 - Manage this breakpoints
 - Add tests for it

JerryScript-DCO-1.0-Signed-off-by: Levente Orban orbanl@inf.u-szeged.hu
This commit is contained in:
Levente Orban 2017-05-18 09:00:38 +02:00 committed by Zoltan Herczeg
parent 31cd3b8020
commit 0806c16902
8 changed files with 148 additions and 14 deletions

View File

@ -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,6 +773,12 @@ def set_breakpoint(debugger, string):
if not found:
print("Breakpoint not found")
if pending:
if line:
debugger.pending_breakpoint_list.append(line)
else:
debugger.pending_breakpoint_list.append(string)
print ("Pending breakpoint added")
return

View File

@ -4,7 +4,8 @@ Stopped at tests/debugger/do_help.js:15
Documented commands (type help <topic>):
========================================
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

View File

@ -0,0 +1,6 @@
fbreak f
list pending
n
n
c
c

View File

@ -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 <unknown>:1 (in f() at line:1, col:1)
Stopped at tests/debugger/do_pending_breakpoints.js:19
(jerry-debugger) c
Stopped at breakpoint:1 <unknown>:1 (in f() at line:1, col:1)
(jerry-debugger) c
Connection closed.

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;