Skip to content

Commit 19d3d25

Browse files
committed
idf_monitor: Aggressively clean up any interactive gdb session
At least on Linux, this can get stuck sometimes and cause terminal weirdness.
1 parent 8ef7434 commit 19d3d25

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/idf_monitor.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,25 @@ def run_gdb(self):
443443
with self: # disable console control
444444
sys.stderr.write(ANSI_NORMAL)
445445
try:
446-
subprocess.call(["%sgdb" % self.toolchain_prefix,
446+
process = subprocess.Popen(["%sgdb" % self.toolchain_prefix,
447447
"-ex", "set serial baud %d" % self.serial.baudrate,
448448
"-ex", "target remote %s" % self.serial.port,
449449
"-ex", "interrupt", # monitor has already parsed the first 'reason' command, need a second
450450
self.elf_file], cwd=".")
451+
process.wait()
451452
except KeyboardInterrupt:
452453
pass # happens on Windows, maybe other OSes
454+
finally:
455+
try:
456+
# on Linux, maybe other OSes, gdb sometimes seems to be alive even after wait() returns...
457+
process.terminate()
458+
except:
459+
pass
460+
try:
461+
# also on Linux, maybe other OSes, gdb sometimes exits uncleanly and breaks the tty mode
462+
subprocess.call(["stty", "sane"])
463+
except:
464+
pass # don't care if there's no stty, we tried...
453465
self.prompt_next_action("gdb exited")
454466

455467
def output_enable(self, enable):

0 commit comments

Comments
 (0)