Skip to content

Commit c00a5e6

Browse files
committed
Improve python debugger client.
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 zherczeg.u-szeged@partner.samsung.com
1 parent ba76b50 commit c00a5e6

File tree

6 files changed

+233
-274
lines changed

6 files changed

+233
-274
lines changed

jerry-debugger/jerry_client.py

Lines changed: 46 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def __init__(self, debugger):
3131
self.debugger = debugger
3232
self.stop = False
3333
self.quit = False
34-
self.backtrace = True
35-
self.debugger.non_interactive = False
3634

3735
def precmd(self, line):
3836
self.stop = False
@@ -60,54 +58,49 @@ def do_display(self, args):
6058

6159
def do_break(self, args):
6260
""" 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())
61+
sys.stdout.write(self.debugger.set_break(args))
6762
do_b = do_break
6863

6964
def do_list(self, _):
7065
""" Lists the available breakpoints """
71-
result = self.debugger.show_breakpoint_list()
72-
print(result.get_data())
66+
sys.stdout.write(self.debugger.breakpoint_list())
7367

7468
def do_delete(self, args):
7569
""" 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())
70+
sys.stdout.write(self.debugger.delete(args))
7971

8072
def do_next(self, args):
8173
""" Next breakpoint in the same context """
8274
self.stop = True
83-
if self.debugger.check_empty_data(args):
75+
if not args:
8476
args = 0
8577
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()
78+
return
79+
80+
try:
81+
args = int(args)
82+
if args <= 0:
83+
raise ValueError(args)
84+
85+
while args > 0:
86+
self.debugger.next()
87+
time.sleep(0.1)
88+
89+
while True:
90+
result = self.debugger.process_messages()
91+
res_type = result.get_type()
92+
93+
if res_type == result.END:
94+
self.quit = True
95+
return
96+
elif res_type == result.TEXT:
97+
sys.stdout.write(result.get_text())
98+
elif res_type == result.PROMPT:
99+
break
100+
101+
args -= 1
102+
except ValueError as val_errno:
103+
print("Error: expected a positive integer: %s" % val_errno)
111104
do_n = do_next
112105

113106
def do_step(self, _):
@@ -118,22 +111,16 @@ def do_step(self, _):
118111

119112
def do_backtrace(self, args):
120113
""" 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
114+
sys.stdout.write(self.debugger.backtrace(args))
115+
self.stop = True
129116
do_bt = do_backtrace
130117

131118
def do_src(self, args):
132119
""" Get current source code """
133120
if args:
134121
line_num = src_check_args(args)
135122
if line_num >= 0:
136-
print(self.debugger.print_source(line_num, 0).get_data())
123+
sys.stdout.write(self.debugger.print_source(line_num, 0))
137124
do_source = do_src
138125

139126
def do_scroll(self, _):
@@ -153,7 +140,7 @@ def do_continue(self, _):
153140
""" Continue execution """
154141
self.debugger.get_continue()
155142
self.stop = True
156-
if self.debugger.check_empty_data(self.debugger.non_interactive):
143+
if not self.debugger.non_interactive:
157144
print("Press enter to stop JavaScript execution.")
158145
do_c = do_continue
159146

@@ -200,8 +187,7 @@ def do_throw(self, args):
200187

201188
def do_exception(self, args):
202189
""" Config the exception handler module """
203-
result = self.debugger.exception(args)
204-
print(result.get_data())
190+
sys.stdout.write(self.debugger.exception(args))
205191

206192
def _scroll_direction(debugger, direction):
207193
""" Helper function for do_scroll """
@@ -229,66 +215,41 @@ def main():
229215
args = jerry_client_ws.arguments_parse()
230216

231217
debugger = jerry_client_ws.JerryDebugger(args.address)
218+
debugger.non_interactive = args.non_interactive
232219

233220
logging.debug("Connected to JerryScript on %d port", debugger.port)
234221

235222
prompt = DebuggerPrompt(debugger)
236223
prompt.prompt = "(jerry-debugger) "
237-
prompt.debugger.non_interactive = args.non_interactive
238224

239225
if args.color:
240226
debugger.set_colors()
241227

242228
if args.display:
243-
prompt.debugger.display = args.display
229+
debugger.display = args.display
244230
prompt.do_display(args.display)
245231
else:
246232
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()
253233

254-
if prompt.debugger.not_empty(args.exception):
234+
if args.exception != None:
255235
prompt.do_exception(str(args.exception))
256236

257237
if args.client_source:
258-
prompt.debugger.store_client_sources(args.client_source)
238+
debugger.store_client_sources(args.client_source)
259239

260240
while True:
261241
if prompt.quit:
262242
break
263243

264-
result = prompt.debugger.mainloop().get_data()
244+
result = debugger.process_messages()
245+
res_type = result.get_type()
265246

266-
if prompt.debugger.check_empty_data(result) and prompt.backtrace is False:
247+
if res_type == result.END:
267248
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()
249+
elif res_type == result.PROMPT:
250+
prompt.cmdloop()
251+
elif res_type == result.TEXT:
252+
sys.stdout.write(result.get_text())
292253
continue
293254

294255
if __name__ == "__main__":

0 commit comments

Comments
 (0)