Skip to content

Commit

Permalink
get pty by tmux command and close pane when gdb exit
Browse files Browse the repository at this point in the history
Signed-off-by: roderick <ch22166@163.com>
  • Loading branch information
roderick committed Sep 13, 2022
1 parent 237760d commit 76461eb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import abc
import argparse
import ast
import atexit
import binascii
import codecs
import collections
Expand Down Expand Up @@ -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]))

gdb.execute(f"! {tmux} send-keys -t {pane} 'clear;sleep infinity' 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!")
Expand Down

0 comments on commit 76461eb

Please sign in to comment.