Skip to content

Commit

Permalink
Explicitly close the remote session (#896)
Browse files Browse the repository at this point in the history
* Explicitly close the remote session

* Add regression test

* Styling fixes
  • Loading branch information
liona24 committed Oct 11, 2022
1 parent 6f7b11a commit f2050af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gef.py
Expand Up @@ -3506,8 +3506,8 @@ def exit_handler(_: "gdb.ExitedEvent") -> None:
reset_all_caches()
gef.session.qemu_mode = False
if gef.session.remote:
# make sure the tempdir is trashed
del(gef.session.remote)
gef.session.remote.close()
del gef.session.remote
gef.session.remote = None
return

Expand Down Expand Up @@ -9964,13 +9964,13 @@ def tmux_setup(self) -> None:
forcing the context to be redirected there."""
tmux = which("tmux")
ok("tmux session found, splitting window...")

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")

ok(f"Setting `context.redirect` to '{pty}'...")
gdb.execute(f"gef config context.redirect {pty}")
ok("Done!")
Expand Down Expand Up @@ -10536,7 +10536,7 @@ def __init__(self, host: str, port: int, pid: int =-1, qemu: Optional[pathlib.Pa
raise EnvironmentError(f"Failed to create a proper environment for {self.target}")
return

def __del__(self) -> None:
def close(self) -> None:
self.__local_root_fd.cleanup()
try:
gef_on_new_unhook(self.remote_objfile_event_handler)
Expand Down
15 changes: 15 additions & 0 deletions tests/regressions/gdbserver_connection.py
@@ -0,0 +1,15 @@
from tests.utils import (
GefUnitTestGeneric,
gdb_run_cmd,
gdbserver_session,
)


class RegressionGdbserverConnection(GefUnitTestGeneric):
def test_can_establish_connection_to_gdbserver_again_after_disconnect(self):
"""Ensure that gdb can connect to a gdbserver again after disconnecting (PR #896)."""

with gdbserver_session(port=5001) as _, gdbserver_session(port=5002) as _:
buf = gdb_run_cmd("gef-remote 127.0.0.1 5001",
after=["detach", "gef-remote 127.0.0.1 5002", "continue"])
self.assertNoException(buf)

0 comments on commit f2050af

Please sign in to comment.