[PATCH v5 1/3] Introduce -l/--syscall-limit option

Dmitry V. Levin ldv at strace.io
Sat Mar 25 19:41:07 UTC 2023


On Mon, Mar 20, 2023 at 11:10:56AM +0530, Sahil Siddiq wrote:
[...]
> @@ -461,6 +462,10 @@ Statistics:\n\
>    -w, --summary-wall-clock\n\
>                   summarise syscall latency (default is system time)\n\
>  \n\
> +Stop condition:\n\
> +  -l LIMIT, --syscall-limit=LIMIT\n\
> +                 Detach tracer after tracing LIMIT syscalls\n\

As strace detaches its tracees, I suggest "Detach all tracees" instead.

[...]
> @@ -3716,6 +3727,10 @@ dispatch_event(const struct tcb_wait_data *wd)
>  			 */
>  			return true;
>  		}
> +		if (syscall_limit == 0) {
> +			detach(current_tcp);
> +			return true;
> +		}

I played with this approach, and found a problem: this way strace detaches
the tracee as soon as an event occurs, so if, for example, a tracee
doesn't invoke syscalls, strace -l won't finish.

I suggest a slightly different approach:
in next_event(), return NULL if syscall_limit == 0, for example:

	if (interrupted)
		return NULL;

	if (syscall_limit == 0) {
		if (!is_number_in_set(QUIET_ATTACH, quiet_set))
			error_msg("System call limit has been reached, detaching tracees");
		strace_child = 0;
		return NULL;
	}

In this case there would be no need to change maybe_allocate_tcb().


-- 
ldv


More information about the Strace-devel mailing list