From f8e1a1f6aeb5ed19120949f761860fdad3279dad Mon Sep 17 00:00:00 2001 From: roderick Date: Fri, 5 Aug 2022 17:12:24 +0800 Subject: [PATCH 1/2] get pty by tmux command and close pane when gdb exit Signed-off-by: roderick --- gef.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gef.py b/gef.py index 0765cc54d..abedb4e70 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,15 @@ 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_info = subprocess.check_output([tmux, "splitw", "-h", '-F#{session_name}:#{window_index}.#{pane_index}-#{pane_tty}', "-P"]).decode().strip().split("-") + pane = pane_info[0] + pty = pane_info[1] + 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!") From 05b77e3d605151121d395121fb213d56e38d9649 Mon Sep 17 00:00:00 2001 From: Roderick <50228047+RoderickChan@users.noreply.github.com> Date: Thu, 29 Sep 2022 11:21:08 +0800 Subject: [PATCH 2/2] Minor edit of pane_info Co-authored-by: crazy hugsy --- gef.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gef.py b/gef.py index abedb4e70..3c95b7862 100644 --- a/gef.py +++ b/gef.py @@ -9964,9 +9964,7 @@ def tmux_setup(self) -> None: tmux = which("tmux") ok("tmux session found, splitting window...") - pane_info = subprocess.check_output([tmux, "splitw", "-h", '-F#{session_name}:#{window_index}.#{pane_index}-#{pane_tty}', "-P"]).decode().strip().split("-") - pane = pane_info[0] - pty = pane_info[1] + 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")