Skip to content

Commit 26e72f2

Browse files
authored
gdb.debug: avoid 2s timeout if possible (#2435)
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.
1 parent 00663aa commit 26e72f2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The table below shows which release corresponds to each branch, and what date th
8888
- [#2405][2405] Add "none" ssh authentication method
8989
- [#2427][2427] Document behaviour of remote()'s sni argument as string.
9090
- [#2382][2382] added optional port, gdb_args and gdbserver_args parameters to gdb.debug()
91+
- [#2435][2435] Speed up gdbserver handshake in gdb.debug()
9192

9293
[2360]: https://github.com/Gallopsled/pwntools/pull/2360
9394
[2356]: https://github.com/Gallopsled/pwntools/pull/2356

pwnlib/gdb.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,13 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
717717

718718
# gdbserver outputs a message when a client connects
719719
garbage = gdbserver.recvline(timeout=1)
720-
721720
# Some versions of gdbserver output an additional message
722-
try:
723-
garbage2 = gdbserver.recvline_startswith(b"Remote debugging from host ", timeout=2)
724-
except EOFError:
725-
pass
721+
message = b"Remote debugging from host "
722+
if not garbage.startswith(message):
723+
try:
724+
garbage2 = gdbserver.recvline_startswith(message, timeout=2)
725+
except EOFError:
726+
pass
726727

727728
return gdbserver
728729

0 commit comments

Comments
 (0)