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()