From: Pedro Alves <palves@redhat.com>
To: Don Breazeal <donb@codesourcery.com>,
"Breazeal, Don" <Don_Breazeal@mentor.com>,
Simon Marchi <simon.marchi@ericsson.com>
Cc: GDB Patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/N] remote follow fork and spurious child stops in non-stop mode
Date: Wed, 29 Jul 2015 13:21:00 -0000 [thread overview]
Message-ID: <55B8D34F.5060002@redhat.com> (raw)
In-Reply-To: <55B2875E.1070504@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 4061 bytes --]
Hi Don,
Sorry for the delay.
On 07/24/2015 07:43 PM, Don Breazeal wrote:
>> index 17b2a51..56a33ff 100644
>> --- a/gdb/gdbserver/linux-low.c
>> +++ b/gdb/gdbserver/linux-low.c
>> @@ -488,6 +488,13 @@ handle_extended_wait (struct lwp_info *event_lwp, int wstat)
>> child_lwp->status_pending_p = 0;
>> child_thr = get_lwp_thread (child_lwp);
>> child_thr->last_resume_kind = resume_stop;
>> + child_thr->last_status.kind = TARGET_WAITKIND_STOPPED;
>
> This makes perfect sense to me.
>
Great.
>> +
>> + /* If we're suspending all threads, leave this one suspended
>> + too. */
>> + if (stopping_threads == STOPPING_AND_SUSPENDING_THREADS)
>> + child_lwp->suspended = 1;
>
> I have a question about this. In the definition of struct lwp_info in
> linux-low.h, it has this comment:
>
> /* When this is true, we shall not try to resume this thread, even
> if last_resume_kind isn't resume_stop. */
> int suspended;
>
> Since we are setting last_resume_kind to resume_stop here, is this
> unnecessary?
We still need it, because otherwise we'd decrement the suspend count
below 0:
static int
unsuspend_and_proceed_one_lwp (struct inferior_list_entry *entry, void *except)
{
struct thread_info *thread = (struct thread_info *) entry;
struct lwp_info *lwp = get_thread_lwp (thread);
if (lwp == except)
return 0;
lwp->suspended--;
gdb_assert (lwp->suspended >= 0);
return proceed_one_lwp (entry, except);
}
It's proceed_one_lwp that skips resuming if the client wants the
lwp stopped:
static int
proceed_one_lwp (struct inferior_list_entry *entry, void *except)
{
...
if (thread->last_resume_kind == resume_stop
&& thread->last_status.kind != TARGET_WAITKIND_IGNORE)
{
if (debug_threads)
debug_printf (" client wants LWP to remain %ld stopped\n",
lwpid_of (thread));
return 0;
}
I tried writing a test for this, by making a multithreaded program
have all its threads but the main continuously fork (see attached), while
the main thread continuously steps over a breakpoint (a conditional
breakpoint with condition "0" should do it, as gdbserver handles
that breakpoint itself), but that stumbles on yet more problems... :-/
$ ./gdb ./testsuite/gdb.threads/fork-plus-threads-2 -ex "set non-stop on" -ex "set detach-on-fork off" -ex "tar extended-rem :9999"
...
Remote debugging using :9999
(gdb)
[Thread 24971.24971] #1 stopped.
0x0000003615a011f0 in ?? ()
c&
Continuing.
(gdb) [New Thread 24971.24981]
[New Thread 24983.24983]
[New Thread 24971.24982]
[Thread 24983.24983] #3 stopped.
0x0000003615ebc7cc in __libc_fork () at ../nptl/sysdeps/unix/sysv/linux/fork.c:130
130 pid = ARCH_FORK ();
[New Thread 24984.24984]
Error in re-setting breakpoint -16: PC register is not available
Error in re-setting breakpoint -17: PC register is not available
Error in re-setting breakpoint -18: PC register is not available
Error in re-setting breakpoint -19: PC register is not available
Error in re-setting breakpoint -24: PC register is not available
Error in re-setting breakpoint -25: PC register is not available
Error in re-setting breakpoint -26: PC register is not available
Error in re-setting breakpoint -27: PC register is not available
Error in re-setting breakpoint -28: PC register is not available
Error in re-setting breakpoint -29: PC register is not available
Error in re-setting breakpoint -30: PC register is not available
PC register is not available
(gdb)
>> set test "reached breakpoint"
BTW, I noticed that this test message is stale from my previous attempt
at running to a breakpoint instead of to exit. I changed it to:
set test "inferior 1 exited"
in patch 1/2.
>> gdb_test_multiple "" $test {
>> + -re "Cannot remove breakpoints" {
>> + set saw_cannot_remove_breakpoints 1
>> + exp_continue
>> + }
>> + -re "Thread \[^\r\n\]+ stopped\\." {
>> + set saw_thread_stopped 1
>> + exp_continue
>> + }
>> -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
>> pass $test
>> }
>> }
Thanks,
Pedro Alves
[-- Attachment #2: fork-plus-threads-2.c --]
[-- Type: text/plain, Size: 2029 bytes --]
/* This testcase is part of GDB, the GNU debugger.
Copyright 2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <assert.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
/* Number of threads. Each thread continuously spawns a fork and wait
for it. If we have another thread continuously start a step over,
gdbserver should end up finding new forks while suspending
threads. */
#define NTHREADS 10
pthread_t threads[NTHREADS];
static void *
thread_func (void *arg)
{
while (1)
{
pid_t pid;
pid = fork ();
if (pid > 0)
{
int status;
/* Parent. */
pid = waitpid (pid, &status, 0);
if (pid == -1)
{
perror ("wait");
exit (1);
}
if (!WIFEXITED (status))
{
printf ("Unexpected wait status 0x%x from child %d\n",
status, pid);
}
}
else if (pid == 0)
{
/* Child. */
exit (0);
}
else
{
perror ("fork");
exit (1);
}
}
}
int
main (void)
{
int i;
int ret;
for (i = 0; i < NTHREADS; i++)
{
ret = pthread_create (&threads[i], NULL, thread_func, NULL);
assert (ret == 0);
}
for (i = 0; i < NTHREADS; i++)
{
ret = pthread_join (threads[i], NULL);
assert (ret == 0);
}
/* Don't run forever. */
sleep (180);
return 0;
}
next prev parent reply other threads:[~2015-07-29 13:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 17:24 [PATCH v2 0/2] PR threads/18600: Threads left stopped after fork+thread spawn Pedro Alves
2015-07-23 17:25 ` [PATCH v2 2/2] PR threads/18600: Inferiors left around " Pedro Alves
2015-07-23 17:25 ` [PATCH v2 1/2] PR threads/18600: Threads left stopped " Pedro Alves
2015-07-30 18:08 ` [pushed] " Pedro Alves
2015-07-23 18:21 ` [PATCH 3/N] remote follow fork and spurious child stops in non-stop mode Pedro Alves
2015-07-24 18:05 ` Simon Marchi
2015-07-24 18:17 ` Pedro Alves
2015-07-24 18:43 ` Don Breazeal
2015-07-29 13:21 ` Pedro Alves [this message]
2015-07-29 13:38 ` Pedro Alves
2015-07-29 14:23 ` Pedro Alves
2015-07-29 15:40 ` Pedro Alves
2015-07-29 16:40 ` Pedro Alves
2015-07-30 18:13 ` Pedro Alves
2015-07-30 18:15 ` Simon Marchi
2015-07-30 21:06 ` Don Breazeal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55B8D34F.5060002@redhat.com \
--to=palves@redhat.com \
--cc=Don_Breazeal@mentor.com \
--cc=donb@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).