From 2b52a43393e78de9c458c23ecdb10280802d9eb9 Mon Sep 17 00:00:00 2001 From: Roderick <50228047+RoderickChan@users.noreply.github.com> Date: Fri, 30 Sep 2022 09:53:24 +0800 Subject: [PATCH] get pty by tmux command and close pane when gdb exit (#881) * get pty by tmux command and close pane when gdb exit Signed-off-by: roderick * Minor edit of pane_info Co-authored-by: crazy hugsy Signed-off-by: roderick Co-authored-by: crazy hugsy --- gef.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gef.py b/gef.py index 0765cc54d..3c95b7862 100644 --- a/gef.py +++ b/gef.py @@ -52,6 +52,7 @@ import abc import argparse import ast +import atexit import binascii import codecs import collections @@ -9962,12 +9963,13 @@ def tmux_setup(self) -> None: forcing the context to be redirected there.""" tmux = which("tmux") ok("tmux session found, splitting window...") - old_ptses = set(os.listdir("/dev/pts")) - gdb.execute(f"! {tmux} split-window -h 'clear ; cat'") + + pane, pty = subprocess.check_output([tmux, "splitw", "-h", '-F#{session_name}:#{window_index}.#{pane_index}-#{pane_tty}', "-P"]).decode().strip().split("-") + atexit.register(lambda : subprocess.run([tmux, "kill-pane", "-t", pane])) + # clear the screen and let it wait for input forever + gdb.execute(f"! {tmux} send-keys -t {pane} 'clear ; cat' C-m") gdb.execute(f"! {tmux} select-pane -L") - new_ptses = set(os.listdir("/dev/pts")) - pty = list(new_ptses - old_ptses)[0] - pty = f"/dev/pts/{pty}" + ok(f"Setting `context.redirect` to '{pty}'...") gdb.execute(f"gef config context.redirect {pty}") ok("Done!")