From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25703 invoked by alias); 12 Apr 2011 13:28:15 -0000 Received: (qmail 25692 invoked by uid 22791); 12 Apr 2011 13:28:14 -0000 X-SWARE-Spam-Status: No, hits=1.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KAM_STOCKTIP,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-vx0-f169.google.com (HELO mail-vx0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Apr 2011 13:28:10 +0000 Received: by vxk20 with SMTP id 20so6386173vxk.0 for ; Tue, 12 Apr 2011 06:28:09 -0700 (PDT) Received: by 10.220.111.80 with SMTP id r16mr722399vcp.9.1302614889146; Tue, 12 Apr 2011 06:28:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.175.197 with HTTP; Tue, 12 Apr 2011 06:27:49 -0700 (PDT) In-Reply-To: <201104121355.11278.pedro@codesourcery.com> References: <201104121159.06026.pedro@codesourcery.com> <201104121355.11278.pedro@codesourcery.com> From: Kevin Pouget Date: Tue, 12 Apr 2011 13:28:00 -0000 Message-ID: Subject: Re: [PATCH] GDB checkpoint can't/shouldn't be possible with multiple threads on Linux To: Pedro Alves Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-04/txt/msg00167.txt.bz2 everything should have been fixed now, > Can you have a dialogue with your mailer, convincing it > to attach text files as Content-Type: text/$SOMETHING > rather than application/octet-stream + base64 ? > It's more steps to to read and harder to quote-for-review > binary attachments than should be necessary. =A0Thanks. gmail is my provider, not easy to talk to them; copy-and-paste should be be= tter > > + =A0gdb_assert(current_inferior() !=3D NULL); > > (Many other things would break if this wasn't true.) that was a redundant verification before checking > > + if (!target_has_execution) error (_("The program is not being run.")= ); so it's now removed > Space before `;' again. =A0Let's reserve variables named > `has_FOO' for booleans. =A0Otherwise, the code is harder > to read (the "if (has_multiple_threads > 1)" check below > made me go "hmm?"). =A0You could encapsulate the magic count > in a predicate function: > > static int > inf_has_multiple_threads (void) > { > =A0int count =3D 0; > > =A0iterate_over_threads (inf_has_multiple_thread_cb, &count); > =A0return (count > 1); > } right, I was afraid of adding to many new functions for a 'simple' bug fix, but it does look better. > Space before `;' again. > ... > Missing spaces again. I'll take an extra care with all these spaces, sorry :) Thanks, Kevin ------ 2011-04-12 Kevin Pouget PR threads/12628 * linux-fork.c (checkpoint_command): Disallow checkpointing of processes with multiple threads. (inf_has_multiple_thread_cb): New function. (inf_has_multiple_threads): New function. ------- diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 7f654af..e733cde 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -616,6 +616,33 @@ linux_fork_checkpointing_p (int pid) return (checkpointing_pid =3D=3D pid); } +/* Callback for iterate over threads. Used to check whether + the current inferior is multi-threaded. Returns true as soon + as it sees the second thread of the current inferior. */ + +static int +inf_has_multiple_thread_cb (struct thread_info *tp, void *data) +{ + int *has_multiple_threads =3D (int *) data; + + if (current_inferior ()->pid =3D=3D ptid_get_pid (tp->ptid)) + (*has_multiple_threads)++; + + /* Stop the iteration if multiple threads have been detected. */ + return *has_multiple_threads > 1; +} + +/* Return true if the current inferior is multi-threaded. */ + +static int +inf_has_multiple_threads (void) +{ + int count =3D 0; + + iterate_over_threads (inf_has_multiple_thread_cb, &count); + return (count > 1); +} + static void checkpoint_command (char *args, int from_tty) { @@ -628,6 +655,14 @@ checkpoint_command (char *args, int from_tty) pid_t retpid; struct cleanup *old_chain; + if (!target_has_execution) + error (_("The program is not being run.")); + + /* Ensure that the inferior is not multithreaded. */ + update_thread_list (); + if (inf_has_multiple_threads ()) + error (_("checkpoint: can't checkpoint multiple threads.")); + /* Make the inferior fork, record its (and gdb's) state. */ if (lookup_minimal_symbol ("fork", NULL, NULL) !=3D NULL)