On Linux, it is not possible to attach to a process after its main thread has exited. Ptrace does not let you attach to zombie threads. E.g., with the gdb.threads/leader-exit.exp test program: $ gdb -p 1804363 ... Attaching to process 1804363 warning: process 1804363 is a zombie - the process has already terminated ptrace: Operation not permitted. (gdb) This is possible on other systems -- at least on Windows it is.
The master branch has been updated by Pedro Alves <palves@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ec48903170926f3827144525b50ddd3c6ae3fbf0 commit ec48903170926f3827144525b50ddd3c6ae3fbf0 Author: Pedro Alves <pedro@palves.net> Date: Mon Mar 25 15:17:02 2024 +0000 New testcase gdb.threads/leader-exit-attach.exp (PR threads/8153) Add a new testcase for exercising attaching to a process after its main thread has exited. This is not possible on Linux, the kernel does not allow attaching to a zombie task, so the test is kfailed there. It is possible however on Windows at least, and was the scenario addressed by the Windows backend fix in https://sourceware.org/legacy-ml/gdb-patches/2003-12/msg00479.html, nowadays PR threads/8153, back in 2003. Passes cleanly on Cygwin. KFAILed on GNU/Linux native and gdbserver. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8153 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31554 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31555 Change-Id: Ib554f92f68c965bb4603cdf2aadb55ca45ded53b