Re: [PATCH 8/8] gdb: resume ongoing step after handling fork or vfork

Simon Marchi via Gdb-patches
2022-04-01T18:43:24Z

>> +#include <pthread.h>
>> +#include <unistd.h>
>> +#include <sys/types.h>
>> +#include <sys/wait.h>
>> +#include <errno.h>
>> +#include <assert.h>
>> +#include <limits.h>
>> +
>> +/* Number of threads doing forks. */
>> +#define N_FORKERS 4
>> +
>> +static void *
>> +forker (void *arg)
>> +{
>> + for (;;)
>> + {
>> + pid_t pid = FORK_FUNC ();
>> +
>> + if (pid == 0)
>> + _exit(11);
>
> Missing space before parens.

Done.

>
>> +
>> + assert (pid > 0);
>> +
>> + /* Wait for children to exit. */
>> + int ret;
>> + int stat;
>> + do {
>
> { on the next line. Thus:

Done (and re-indented the whole do-while). Is there a missing part to
your comment that should come after "Thus:"?

>
>> + ret = waitpid (pid, &stat, 0);
>> + } while (ret == EINTR);
>> +
>> + assert (ret == pid);
>> + assert (WIFEXITED (stat));
>> + assert (WEXITSTATUS (stat) == 11);
>> +
>> + usleep (40 * 1000);
>
> Why not sleep_a_bit()? Is the fact that it's a little less time significant?

Ah, good question. We need the forking threads to fork reasonably
often, if we want the bug to reproduce most of the time. But we need
some sleep, with any sleep the forking threads just spam events and
starve the stepping thread, and we don't really make progress. I'll add
a comment to that effect.

>
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> +static void
>> +sleep_a_bit (void)
>> +{
>> + usleep (1000 * 50);
>> +}
>> +
>> +int
>> +main (void)
>> +{
>> + alarm (60);
>> +
>> + pthread_t thread[N_FORKERS];
>> + for (int i = 0; i < N_FORKERS; ++i)
>
> Declare "int i" outside the loop so this compiles as C90 as well. Ditto below.

Done.

Simon