def display_one_valuable(self, row_num: int): # Avoid infinity loop self.display_widget.cellChanged.disconnect(self.processDisplayEdited) name = self.display_widget.item(row_num, 0).text() if not name: self.display_widget.set_cell(row_num, 1, "") self.display_widget.set_cell(row_num, 2, "") self.display_widget.cellChanged.connect(self.processDisplayEdited) return self.debug_process.send(b"p " + name.encode() + b"\n") util.wait_input_ready(self.debug_process, self.editor.lang) value = "".join(self.debug_process.before.decode().split("\r\n")[1:]) value = value.split(" = ")[-1] # value = ''.join(value.split(' = ')[1:]) self.display_widget.set_cell(row_num, 1, value) if self.editor.lang == "python3": self.debug_process.send(b"whatis " + name.encode() + b"\n") else: self.debug_process.send(b"pt " + name.encode() + b"\n") util.wait_input_ready(self.debug_process, self.editor.lang) type = "".join(self.debug_process.before.decode().split("\n")[1:]) type = type.split(" = ")[-1] type = type.split(" {")[0] self.display_widget.set_cell(row_num, 2, type) self.display_widget.cellChanged.connect(self.processDisplayEdited)
def post_process(self): assert self.debug_process is not None try: util.wait_input_ready( self.debug_process, self.editor.lang, self.gdb_timeout ) except: print(str(self.debug_process)) self.console.writeLnSignal.emit("[-] Debug process is timeout") self.terminate() return msg = self.debug_process.before.decode() for line in msg.split("\r\n"): self.console.writeSignal.emit(WriteObj(line, mode="gdb")) for line in reversed(msg.split("\r\n")): if line.endswith("exited normally]") or line.startswith( "The program finished" ): self.terminate() return elif line.endswith("No such file or directory.") or line.endswith( "そのようなファイルやディレクトリはありません." ): self.stepOut() return elif "exited with code" in line: self.console.writeLnSignal.emit("[-] Process is finished with error") self.terminate() return else: line_num = util.get_executing_line(self.editor.lang, line) if line_num is None: continue self.editor.highlight_executing_line(line_num) self.editor.repaint() break for i, _ in self.display_widget.name_iter(): self.display_one_valuable(i)
def UpdateBreak(self, command: bytes): if self.debug_process is None: return if command.startswith(b"b "): self.debug_process.send(command) util.wait_input_ready(self.debug_process, self.editor.lang) else: self.debug_process.send("i b\n".encode()) util.wait_input_ready(self.debug_process, self.editor.lang) print(self.debug_process.before.decode()) last_num = -1 for line in self.debug_process.before.decode().split("\r\n"): if line.split(" ")[0].isdecimal(): last_num = int(line.split(" ")[0]) if line.rstrip("\n").endswith(":" + command.decode()): assert last_num != -1 self.debug_process.send(("d " + str(last_num) + "\n").encode()) util.wait_input_ready(self.debug_process, self.editor.lang) break
def debug(self, *args, **kwargs): self.console.clear() if not self.compile(): return if self.debug_process is not None: if self.askTerminateOrNot(): self.terminate() else: return compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) if not os.path.isfile(compiled_file): util.disp_error("Compiled file is not found.") try: assert self.debug_process is None self.debug_process = pexpect.spawn( util.debug_command(self.editor.lang) + " " + compiled_file ) util.wait_input_ready(self.debug_process, self.editor.lang) self.console.writeSignal.emit(WriteObj(self.debug_process.before.decode())) for com in self.editor.generateBreak(): self.debug_process.send(com) util.wait_input_ready(self.debug_process, self.editor.lang) self.console.writeSignal.emit( WriteObj(self.debug_process.before.decode(), mode="gdb") ) print("run " + compiled_file) self.debug_process.send(b"run\n") self.updateWindowTitle() if self.editor.lang == "python3": util.wait_input_ready(self.debug_process, self.editor.lang) self.debug_process.send(b"continue\n") self.post_process() except subprocess.CalledProcessError as err: self.console.writeSignal(WriteObj(err, mode="error"))
def debugWithTestData(self, use_lastcase=False): self.console.clear() if not self.compile(): return if self.debug_process is not None: if self.askTerminateOrNot(): self.terminate() else: return if ( use_lastcase and self.last_used_testcase and os.path.isfile(self.last_used_testcase) ): fname = self.last_used_testcase else: fname = QtWidgets.QFileDialog.getOpenFileName( self, "Open", self.test_data_dir, "Test data (*.in)" )[0] if not fname: self.last_used_testcase = "" return self.last_used_testcase = fname with open(fname) as fr: inputs = [line for line in fr if line] compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) if not os.path.isfile(compiled_file): util.disp_error("Compiled file is not found.") try: if self.debug_process is None: self.debug_process = pexpect.spawn( util.debug_command(self.editor.lang) + " " + compiled_file ) self.console.terminate_evcxr() else: self.continue_process() return util.wait_input_ready(self.debug_process, self.editor.lang) for com in self.editor.generateBreak(): self.debug_process.send(com) util.wait_input_ready(self.debug_process, self.editor.lang) self.console.writeSignal.emit( WriteObj(self.debug_process.before.decode(), mode="gdb") ) print("run " + compiled_file) self.debug_process.send(b"run\n") self.updateWindowTitle() if self.editor.lang == "python3": util.wait_input_ready(self.debug_process, self.editor.lang) self.debug_process.send(b"continue\n") for i, debug_input in enumerate(inputs): msg = self.debug_process.before.decode() for line in msg.split("\r\n"): self.console.writeSignal.emit(WriteObj(line, mode="gdb")) for line in reversed(msg.split("\r\n")): if line.endswith("exited normally]"): if i != len(inputs) - 1: self.console.writeLnSignal.emit( "[-] Partial input is rejected" ) self.terminate() return if "exited with code" in line: self.console.writeLnSignal.emit( "[-] Process is finished with error" ) self.terminate() return self.debug_process.send(debug_input.encode()) self.post_process() self.updateWindowTitle() self.console.run_evcxr() except subprocess.CalledProcessError as err: self.console.writeSignal.emit(WriteObj(err, mode="error")) self.console.run_evcxr()