|
72 | 72 | ESCARGOT_DEBUGGER_WAIT_FOR_SOURCE = 43 |
73 | 73 | ESCARGOT_DEBUGGER_WAITING_AFTER_PENDING = 44 |
74 | 74 | ESCARGOT_DEBUGGER_WAIT_FOR_WAIT_EXIT = 45 |
| 75 | +ESCARGOT_MESSAGE_WATCH_RESULT_8BIT = 46 |
| 76 | +ESCARGOT_MESSAGE_WATCH_RESULT_8BIT_END = 47 |
| 77 | +ESCARGOT_MESSAGE_WATCH_RESULT_16BIT = 48 |
| 78 | +ESCARGOT_MESSAGE_WATCH_RESULT_16BIT_END = 49 |
75 | 79 |
|
76 | 80 |
|
77 | 81 | # Messages sent by the debugger client to Escargot. |
|
101 | 105 | ESCARGOT_DEBUGGER_PENDING_CONFIG = 23 |
102 | 106 | ESCARGOT_DEBUGGER_PENDING_RESUME = 24 |
103 | 107 | ESCARGOT_DEBUGGER_WAIT_BEFORE_EXIT = 25 |
| 108 | +ESCARGOT_DEBUGGER_STOP = 26 |
| 109 | +ESCARGOT_MESSAGE_WATCH_8BIT_START = 27 |
| 110 | +ESCARGOT_MESSAGE_WATCH_8BIT = 28 |
| 111 | +ESCARGOT_MESSAGE_WATCH_16BIT_START = 29 |
| 112 | +ESCARGOT_MESSAGE_WATCH_16BIT = 30 |
104 | 113 |
|
105 | 114 |
|
106 | 115 | # Environment record types |
@@ -300,6 +309,8 @@ def __init__(self, channel): |
300 | 309 | self.next_breakpoint_index = 0 |
301 | 310 | self.active_breakpoint_list = {} |
302 | 311 | self.pending_breakpoint_list = {} |
| 312 | + self.watched_values_list = [] |
| 313 | + self.waiting_for_watched_values_count = 0 |
303 | 314 | self.line_list = Multimap() |
304 | 315 | self.display = 0 |
305 | 316 | self.green = '' |
@@ -442,6 +453,15 @@ def process_messages(self): |
442 | 453 | self.prompt = True |
443 | 454 | return DebuggerAction(DebuggerAction.TEXT, self._receive_string(ESCARGOT_MESSAGE_EVAL_RESULT_8BIT, data)) |
444 | 455 |
|
| 456 | + elif buffer_type in [ESCARGOT_MESSAGE_WATCH_RESULT_8BIT, |
| 457 | + ESCARGOT_MESSAGE_WATCH_RESULT_8BIT_END, |
| 458 | + ESCARGOT_MESSAGE_WATCH_RESULT_16BIT, |
| 459 | + ESCARGOT_MESSAGE_WATCH_RESULT_16BIT_END]: |
| 460 | + self.prompt = True |
| 461 | + self.waiting_for_watched_values_count -= 1 |
| 462 | + print("Watch: " + self._receive_string(ESCARGOT_MESSAGE_WATCH_RESULT_8BIT, data)) |
| 463 | + return DebuggerAction(DebuggerAction.WAIT, "") |
| 464 | + |
445 | 465 | elif buffer_type in [ESCARGOT_MESSAGE_EVAL_FAILED_8BIT, |
446 | 466 | ESCARGOT_MESSAGE_EVAL_FAILED_8BIT_END, |
447 | 467 | ESCARGOT_MESSAGE_EVAL_FAILED_16BIT, |
@@ -588,7 +608,7 @@ def send_client_source(self): |
588 | 608 | self._exec_command(ESCARGOT_DEBUGGER_THERE_WAS_NO_SOURCE) |
589 | 609 | return |
590 | 610 | path = self.client_sources.pop(0) |
591 | | - if not path.endswith('.js'): |
| 611 | + if not path.endswith('.js') and not path.endswith('.mjs'): |
592 | 612 | sys.exit("Error: Javascript file expected!") |
593 | 613 | with open(path, 'r') as src_file: |
594 | 614 | content = path + '\0'+ src_file.read() |
@@ -646,6 +666,16 @@ def set_break(self, args): |
646 | 666 |
|
647 | 667 | return self._set_breakpoint(args, False) |
648 | 668 |
|
| 669 | + def set_watch(self, args): |
| 670 | + if not args: |
| 671 | + return "Error: Value name expected" |
| 672 | + |
| 673 | + if args not in self.watched_values_list: |
| 674 | + self.watched_values_list.append(args) |
| 675 | + return "Added watch: %s\n" % args |
| 676 | + else: |
| 677 | + return "Already watching: %s\n" % args |
| 678 | + |
649 | 679 | def delete(self, args): |
650 | 680 | if not args: |
651 | 681 | return "Error: Breakpoint index expected\n" \ |
@@ -734,8 +764,21 @@ def print_source(self, line_num, offset): |
734 | 764 |
|
735 | 765 | return msg |
736 | 766 |
|
737 | | - def eval(self, code): |
738 | | - self._send_string(code, ESCARGOT_MESSAGE_EVAL_8BIT_START) |
| 767 | + def print_watches(self): |
| 768 | + if self.watched_values_list: |
| 769 | + for var_name in self.watched_values_list: |
| 770 | + self.eval(var_name, watch=True) |
| 771 | + self.waiting_for_watched_values_count += 1 |
| 772 | + while self.waiting_for_watched_values_count > 0: |
| 773 | + self.process_messages() |
| 774 | + |
| 775 | + def list_watches(self): |
| 776 | + print("Watched values:") |
| 777 | + for var_name in self.watched_values_list: |
| 778 | + print(var_name) |
| 779 | + |
| 780 | + def eval(self, code, watch=False): |
| 781 | + self._send_string(code, ESCARGOT_MESSAGE_EVAL_8BIT_START if not watch else ESCARGOT_MESSAGE_WATCH_8BIT_START) |
739 | 782 | self.prompt = False |
740 | 783 |
|
741 | 784 | def backtrace(self, args): |
@@ -1165,3 +1208,7 @@ def breakpoint_pending_exists(self, breakpoint): |
1165 | 1208 | return True |
1166 | 1209 |
|
1167 | 1210 | return False |
| 1211 | + |
| 1212 | + def delete_watch(self, var_name): |
| 1213 | + self.watched_values_list.remove(var_name) |
| 1214 | + return "Removed watch: %s\n" % var_name |
0 commit comments