This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Stop threads when attaching to a PID that is the tgid
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org, lgustavo at codesourcery dot com
- Date: Tue, 23 Aug 2011 18:48:14 +0100
- Subject: Re: [PATCH] Stop threads when attaching to a PID that is the tgid
- References: <4E53B25B.3030009@codesourcery.com>
On Tuesday 23 August 2011 14:59:55, Luis Machado wrote:
> Hi,
>
Missing explanation as to _why_ we need this. Here's one:
On linux/ptrace, a ptracer needs to attach to each
and every thread of a process individually. Currently, when you
do `gdbserver --attach PID', GDBserver only attaches to the PID thread,
leaving all the other threads of the process running free. This is because
GDBserver relies on thread_db to list the threads of PID, and, in order
to activate thread_db, GDBserver needs to query GDB about some symbols,
which obviously can only work once GDB connects..
To fix this, this patch teaches GDBServer to list threads using /proc,
instead of relying on thread_db, and attach/stop all of them.
> This patch teaches GDBServer how to stop threads from a TID that is also
> the TGID, without having to rely on GDB to list and stop them upon
> connection.
> 2011-08-23 Luis Machado <lgustavo@codesourcery.com>
>
> * linux-low.c: Include linux-procfs.h.
> (linux_attach_lwp_1): Update comments.
> (linux_attach): Scan for existing threads when attaching to a
> process that is the tgid.
>
> --- .pc/stop_threads.diff/gdb/gdbserver/linux-low.c 2011-08-23 10:38:50.653049001 -0300
> +++ gdb/gdbserver/linux-low.c 2011-08-23 10:58:02.817049000 -0300
> @@ -26,6 +26,7 @@
> #include <sys/param.h>
> #include <sys/ptrace.h>
> #include "linux-ptrace.h"
> +#include "linux-procfs.h"
Sorry I missed this before. This needs an update to the linux-low.o
rule in Makefile.in. gdbserver doesn't do automatic header
dependencies... This is okay otherwise.
--
Pedro Alves