From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30034 invoked by alias); 12 Apr 2011 13:55:08 -0000 Received: (qmail 30022 invoked by uid 22791); 12 Apr 2011 13:55:07 -0000 X-SWARE-Spam-Status: No, hits=1.2 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:55:03 +0000 Received: by vxk20 with SMTP id 20so6418983vxk.0 for ; Tue, 12 Apr 2011 06:55:03 -0700 (PDT) Received: by 10.220.111.80 with SMTP id r16mr731045vcp.9.1302616503112; Tue, 12 Apr 2011 06:55:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.175.197 with HTTP; Tue, 12 Apr 2011 06:54:43 -0700 (PDT) In-Reply-To: <201104121441.56034.pedro@codesourcery.com> References: <201104121355.11278.pedro@codesourcery.com> <201104121441.56034.pedro@codesourcery.com> From: Kevin Pouget Date: Tue, 12 Apr 2011 13:55: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/msg00171.txt.bz2 On Tue, Apr 12, 2011 at 9:41 AM, Pedro Alves wrote: > Small nit I should have caught before: > > On Tuesday 12 April 2011 14:27:49, Kevin Pouget wrote: >> +static int >> +inf_has_multiple_thread_cb (struct thread_info *tp, void *data) >> +{ >> + =A0int *has_multiple_threads =3D (int *) data; > > can you rename this local as well, in line with the other > local in the other function? =A0To "count", or "count_p", or something > like that. =A0Thanks. =A0(pre-approved) fixed with count_p, 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..de512c3 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 *count_p =3D (int *) data; + + if (current_inferior ()->pid =3D=3D ptid_get_pid (tp->ptid)) + (*count_p)++; + + /* Stop the iteration if multiple threads have been detected. */ + return *count_p > 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)