Record output until the gdb prompt displays. Return recorded output.
(self)
| 97 | self.last_stdout_line = b"" |
| 98 | |
| 99 | def wait_until_ready(self): |
| 100 | """ |
| 101 | Record output until the gdb prompt displays. Return recorded output. |
| 102 | """ |
| 103 | # TODO: add timeout? |
| 104 | while (not self.last_stdout_line.startswith(b"(gdb) ") and |
| 105 | self.proc.poll() is None): |
| 106 | block = self.proc.stdout.read(4096) |
| 107 | if self.verbose: |
| 108 | sys.stdout.buffer.write(block) |
| 109 | sys.stdout.buffer.flush() |
| 110 | block, sep, last_line = block.rpartition(b"\n") |
| 111 | if sep: |
| 112 | self.last_stdout.append(self.last_stdout_line) |
| 113 | self.last_stdout.append(block + sep) |
| 114 | self.last_stdout_line = last_line |
| 115 | else: |
| 116 | assert block == b"" |
| 117 | self.last_stdout_line += last_line |
| 118 | |
| 119 | if self.proc.poll() is not None: |
| 120 | raise IOError("gdb session terminated unexpectedly") |
| 121 | |
| 122 | out = b"".join(self.last_stdout).decode('utf-8') |
| 123 | self.last_stdout = [] |
| 124 | self.last_stdout_line = b"" |
| 125 | return out |
| 126 | |
| 127 | def issue_command(self, line): |
| 128 | line = line.encode('utf-8') + b"\n" |