Skip to content

Commit 300e40b

Browse files
authored
Improve python debugger client. (#2441)
Replace DisplayData to DebuggerAction. The new class has only four type options. Furthermore several functions returning with DisplayData is changed to return with string. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent b2cf7eb commit 300e40b

File tree

8 files changed

+265
-316
lines changed

8 files changed

+265
-316
lines changed

jerry-core/debugger/debugger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ typedef struct
367367
typedef struct
368368
{
369369
uint8_t type; /**< type of the message */
370-
uint8_t frame_count[sizeof (uint32_t)]; /**< total number of frames*/
370+
uint8_t frame_count[sizeof (uint32_t)]; /**< total number of frames */
371371
} jerry_debugger_send_backtrace_total_t;
372372

373373
/**

jerry-debugger/jerry_client.py

Lines changed: 49 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
import time
2525
import jerry_client_ws
2626

27+
def write(string):
28+
print(string, end='')
29+
2730
class DebuggerPrompt(Cmd):
2831
# pylint: disable=too-many-instance-attributes,too-many-arguments
2932
def __init__(self, debugger):
3033
Cmd.__init__(self)
3134
self.debugger = debugger
3235
self.stop = False
3336
self.quit = False
34-
self.backtrace = True
35-
self.debugger.non_interactive = False
3637

3738
def precmd(self, line):
3839
self.stop = False
@@ -60,54 +61,49 @@ def do_display(self, args):
6061

6162
def do_break(self, args):
6263
""" Insert breakpoints on the given lines or functions """
63-
result = ""
64-
result = self.debugger.set_break(args)
65-
if self.debugger.not_empty(result):
66-
print(result.get_data())
64+
write(self.debugger.set_break(args))
6765
do_b = do_break
6866

6967
def do_list(self, _):
7068
""" Lists the available breakpoints """
71-
result = self.debugger.show_breakpoint_list()
72-
print(result.get_data())
69+
write(self.debugger.breakpoint_list())
7370

7471
def do_delete(self, args):
7572
""" Delete the given breakpoint, use 'delete all|active|pending' to clear all the given breakpoints """
76-
result = self.debugger.delete(args)
77-
if self.debugger.not_empty(result):
78-
print(result.get_data())
73+
write(self.debugger.delete(args))
7974

8075
def do_next(self, args):
8176
""" Next breakpoint in the same context """
8277
self.stop = True
83-
if self.debugger.check_empty_data(args):
78+
if not args:
8479
args = 0
8580
self.debugger.next()
86-
else:
87-
try:
88-
args = int(args)
89-
if args <= 0:
90-
raise ValueError(args)
91-
else:
92-
while int(args) != 0:
93-
self.debugger.next()
94-
time.sleep(0.5)
95-
result = self.debugger.mainloop().get_data()
96-
if result.endswith('\n'):
97-
result = result.rstrip()
98-
if jerry_client_ws.JERRY_DEBUGGER_DATA_END in result:
99-
result = result.replace(jerry_client_ws.JERRY_DEBUGGER_DATA_END, '')
100-
if result:
101-
print(result)
102-
self.debugger.smessage = ''
103-
if self.debugger.display > 0:
104-
print(self.debugger.print_source(self.debugger.display,
105-
self.debugger.src_offset).get_data())
106-
args = int(args) - 1
107-
self.cmdloop()
108-
except ValueError as val_errno:
109-
print("Error: expected a positive integer: %s" % val_errno)
110-
self.cmdloop()
81+
return
82+
83+
try:
84+
args = int(args)
85+
if args <= 0:
86+
raise ValueError(args)
87+
88+
while args > 0:
89+
self.debugger.next()
90+
time.sleep(0.1)
91+
92+
while True:
93+
result = self.debugger.process_messages()
94+
res_type = result.get_type()
95+
96+
if res_type == result.END:
97+
self.quit = True
98+
return
99+
elif res_type == result.TEXT:
100+
write(result.get_text())
101+
elif res_type == result.PROMPT:
102+
break
103+
104+
args -= 1
105+
except ValueError as val_errno:
106+
print("Error: expected a positive integer: %s" % val_errno)
111107
do_n = do_next
112108

113109
def do_step(self, _):
@@ -118,22 +114,16 @@ def do_step(self, _):
118114

119115
def do_backtrace(self, args):
120116
""" Get backtrace data from debugger """
121-
result = self.debugger.backtrace(args)
122-
if self.debugger.not_empty(result):
123-
print(result.get_data())
124-
self.stop = True
125-
self.cmdloop()
126-
else:
127-
self.stop = True
128-
self.backtrace = True
117+
write(self.debugger.backtrace(args))
118+
self.stop = True
129119
do_bt = do_backtrace
130120

131121
def do_src(self, args):
132122
""" Get current source code """
133123
if args:
134124
line_num = src_check_args(args)
135125
if line_num >= 0:
136-
print(self.debugger.print_source(line_num, 0).get_data())
126+
write(self.debugger.print_source(line_num, 0))
137127
do_source = do_src
138128

139129
def do_scroll(self, _):
@@ -153,7 +143,7 @@ def do_continue(self, _):
153143
""" Continue execution """
154144
self.debugger.get_continue()
155145
self.stop = True
156-
if self.debugger.check_empty_data(self.debugger.non_interactive):
146+
if not self.debugger.non_interactive:
157147
print("Press enter to stop JavaScript execution.")
158148
do_c = do_continue
159149

@@ -200,8 +190,7 @@ def do_throw(self, args):
200190

201191
def do_exception(self, args):
202192
""" Config the exception handler module """
203-
result = self.debugger.exception(args)
204-
print(result.get_data())
193+
write(self.debugger.exception(args))
205194

206195
def _scroll_direction(debugger, direction):
207196
""" Helper function for do_scroll """
@@ -229,66 +218,41 @@ def main():
229218
args = jerry_client_ws.arguments_parse()
230219

231220
debugger = jerry_client_ws.JerryDebugger(args.address)
221+
debugger.non_interactive = args.non_interactive
232222

233223
logging.debug("Connected to JerryScript on %d port", debugger.port)
234224

235225
prompt = DebuggerPrompt(debugger)
236226
prompt.prompt = "(jerry-debugger) "
237-
prompt.debugger.non_interactive = args.non_interactive
238227

239228
if args.color:
240229
debugger.set_colors()
241230

242231
if args.display:
243-
prompt.debugger.display = args.display
232+
debugger.display = args.display
244233
prompt.do_display(args.display)
245234
else:
246235
prompt.stop = False
247-
if prompt.debugger.check_empty_data(args.client_source):
248-
prompt.debugger.mainloop()
249-
result = prompt.debugger.smessage
250-
print(result)
251-
prompt.debugger.smessage = ''
252-
prompt.cmdloop()
253236

254-
if prompt.debugger.not_empty(args.exception):
237+
if args.exception is not None:
255238
prompt.do_exception(str(args.exception))
256239

257240
if args.client_source:
258-
prompt.debugger.store_client_sources(args.client_source)
241+
debugger.store_client_sources(args.client_source)
259242

260243
while True:
261244
if prompt.quit:
262245
break
263246

264-
result = prompt.debugger.mainloop().get_data()
247+
result = debugger.process_messages()
248+
res_type = result.get_type()
265249

266-
if prompt.debugger.check_empty_data(result) and prompt.backtrace is False:
250+
if res_type == result.END:
267251
break
268-
269-
if prompt.debugger.wait_data(result):
270-
continue
271-
272-
elif jerry_client_ws.JERRY_DEBUGGER_DATA_END in result:
273-
result = result.replace(jerry_client_ws.JERRY_DEBUGGER_DATA_END, '')
274-
if result.endswith('\n'):
275-
result = result.rstrip()
276-
if result:
277-
print(result)
278-
prompt.debugger.smessage = ''
279-
if prompt.debugger.display > 0:
280-
print(prompt.debugger.print_source(prompt.debugger.display, prompt.debugger.src_offset).get_data())
281-
prompt.backtrace = False
282-
break
283-
else:
284-
if result.endswith('\n'):
285-
result = result.rstrip()
286-
if result:
287-
print(result)
288-
prompt.debugger.smessage = ''
289-
if prompt.debugger.display > 0:
290-
print(prompt.debugger.print_source(prompt.debugger.display, prompt.debugger.src_offset).get_data())
291-
prompt.cmdloop()
252+
elif res_type == result.PROMPT:
253+
prompt.cmdloop()
254+
elif res_type == result.TEXT:
255+
write(result.get_text())
292256
continue
293257

294258
if __name__ == "__main__":

0 commit comments

Comments
 (0)