Skip to content

Commit

Permalink
gdb.debug: avoid 2s timeout if possible
Browse files Browse the repository at this point in the history
On Ubuntu 22.04 gdb.debug() takes at least 2 seconds. This is because
it prints only "Remote debugging from host 127.0.0.1, port 33398", but
the code expects 2 lines.

It's very unclear what the second line is supposed to be; the only lead
is "* Handle extra newline printed by gdb" in commit 338fbeb ("Improve
pwnup template, gdbserver detection (#1148)"), but I could not trace it
back to the GDB source code, both historic and modern. Perhaps, there
is a non-upstreamed patch in some distro that introduces it.

It should still be safe to skip waiting for the second line if the
first one already starts with "Remote debugging ...", so do it.
  • Loading branch information
mephi42 committed Aug 4, 2024
1 parent 00663aa commit 6e7c0fd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pwnlib/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,13 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por

# gdbserver outputs a message when a client connects
garbage = gdbserver.recvline(timeout=1)

# Some versions of gdbserver output an additional message
try:
garbage2 = gdbserver.recvline_startswith(b"Remote debugging from host ", timeout=2)
except EOFError:
pass
message = b"Remote debugging from host "
if not garbage.startswith(message):
try:
garbage2 = gdbserver.recvline_startswith(message, timeout=2)
except EOFError:
pass

return gdbserver

Expand Down

0 comments on commit 6e7c0fd

Please sign in to comment.