mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
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:
parent
31cd3b8020
commit
0806c16902
@ -159,12 +159,6 @@ class DebuggerPrompt(Cmd):
|
|||||||
def postcmd(self, stop, line):
|
def postcmd(self, stop, line):
|
||||||
return self.stop
|
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):
|
def disable_args(self, args):
|
||||||
if args:
|
if args:
|
||||||
print("Error: No argument expected")
|
print("Error: No argument expected")
|
||||||
@ -180,11 +174,21 @@ class DebuggerPrompt(Cmd):
|
|||||||
self.quit = True
|
self.quit = True
|
||||||
|
|
||||||
def do_break(self, args):
|
def do_break(self, args):
|
||||||
""" Insert breakpoints on the given lines """
|
""" Insert breakpoints on the given lines or functions """
|
||||||
self.insert_breakpoint(args)
|
if args == "":
|
||||||
|
print("Error: Breakpoint index expected")
|
||||||
|
else:
|
||||||
|
set_breakpoint(self.debugger, False, args)
|
||||||
|
|
||||||
do_b = do_break
|
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):
|
def exec_command(self, args, command_id):
|
||||||
self.stop = True
|
self.stop = True
|
||||||
if args != "":
|
if args != "":
|
||||||
@ -217,8 +221,10 @@ class DebuggerPrompt(Cmd):
|
|||||||
do_n = do_next
|
do_n = do_next
|
||||||
|
|
||||||
def do_list(self, args):
|
def do_list(self, args):
|
||||||
""" Lists the available breakpoints """
|
""" Lists the available breakpoints, use 'pending' to list all the available pending breakpoints """
|
||||||
if self.disable_args(args):
|
if args == "pending":
|
||||||
|
for index, breakpoint in enumerate(self.debugger.pending_breakpoint_list):
|
||||||
|
print("%d: %s" % (index, breakpoint))
|
||||||
return
|
return
|
||||||
|
|
||||||
for breakpoint in self.debugger.active_breakpoint_list.values():
|
for breakpoint in self.debugger.active_breakpoint_list.values():
|
||||||
@ -250,6 +256,28 @@ class DebuggerPrompt(Cmd):
|
|||||||
else:
|
else:
|
||||||
print("Error: Breakpoint %d not found" % (breakpoint_index))
|
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):
|
def exec_backtrace(self, args):
|
||||||
max_depth = 0
|
max_depth = 0
|
||||||
|
|
||||||
@ -408,6 +436,7 @@ class JerryDebugger(object):
|
|||||||
self.last_breakpoint_hit = None
|
self.last_breakpoint_hit = None
|
||||||
self.next_breakpoint_index = 0
|
self.next_breakpoint_index = 0
|
||||||
self.active_breakpoint_list = {}
|
self.active_breakpoint_list = {}
|
||||||
|
self.pending_breakpoint_list = []
|
||||||
self.line_list = Multimap()
|
self.line_list = Multimap()
|
||||||
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.client_socket.connect((self.host, self.port))
|
self.client_socket.connect((self.host, self.port))
|
||||||
@ -678,6 +707,17 @@ def parse_source(debugger, data):
|
|||||||
for line, breakpoint in function.lines.items():
|
for line, breakpoint in function.lines.items():
|
||||||
debugger.line_list.insert(line, breakpoint)
|
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):
|
def release_function(debugger, data):
|
||||||
byte_code_cp = struct.unpack(debugger.byte_order + debugger.cp_format,
|
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))
|
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)
|
line = re.match("(.*):(\\d+)$", string)
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
@ -733,7 +773,13 @@ def set_breakpoint(debugger, string):
|
|||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
print("Breakpoint 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):
|
def get_breakpoint(debugger, breakpoint_data):
|
||||||
|
|||||||
@ -4,7 +4,8 @@ Stopped at tests/debugger/do_help.js:15
|
|||||||
|
|
||||||
Documented commands (type help <topic>):
|
Documented commands (type help <topic>):
|
||||||
========================================
|
========================================
|
||||||
b break c delete e exception list next s step
|
b bt delete eval help next s
|
||||||
backtrace bt continue dump eval help n quit src
|
backtrace c dump exception list pendingdel src
|
||||||
|
break continue e fbreak n quit step
|
||||||
|
|
||||||
(jerry-debugger) quit
|
(jerry-debugger) quit
|
||||||
|
|||||||
6
tests/debugger/do_pending_breakpoints.cmd
Normal file
6
tests/debugger/do_pending_breakpoints.cmd
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
fbreak f
|
||||||
|
list pending
|
||||||
|
n
|
||||||
|
n
|
||||||
|
c
|
||||||
|
c
|
||||||
16
tests/debugger/do_pending_breakpoints.expected
Normal file
16
tests/debugger/do_pending_breakpoints.expected
Normal 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.
|
||||||
21
tests/debugger/do_pending_breakpoints.js
Normal file
21
tests/debugger/do_pending_breakpoints.js
Normal 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;
|
||||||
6
tests/debugger/do_pending_list.cmd
Normal file
6
tests/debugger/do_pending_list.cmd
Normal 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
|
||||||
18
tests/debugger/do_pending_list.expected
Normal file
18
tests/debugger/do_pending_list.expected
Normal 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
|
||||||
20
tests/debugger/do_pending_list.js
Normal file
20
tests/debugger/do_pending_list.js
Normal 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;
|
||||||
Loading…
x
Reference in New Issue
Block a user