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

Pedro Alves
2022-03-31T18:28:58Z

[Lol, I reviewed this one twice, and the first time forgot to press send.]

This is OK. Small nits in the testcase below.

On 2022-01-17 16:27, Simon Marchi via Gdb-patches wrote:

> +#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.

> +
> + assert (pid > 0);
> +
> + /* Wait for children to exit. */
> + int ret;
> + int stat;
> + do {

{ on the next line. 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?

> + }
> +
> + 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.

> + {
> + int ret = pthread_create (&thread[i], NULL, forker, NULL);
> + assert (ret == 0);
> + }
> +
> + for (int i = 0; i < INT_MAX; ++i) /* for loop */
> + {
> + sleep_a_bit (); /* break here */
> + sleep_a_bit (); /* other line */
> + }
> +
> + for (int i = 0; i < N_FORKERS; ++i)
> + pthread_join (thread[i], NULL);
> +
> + return 0;
> +}