[PATCH v3] strace.c: refactor trace into two functions

Dmitry V. Levin ldv at altlinux.org
Sun Jun 4 13:50:35 UTC 2017


On Fri, Jun 02, 2017 at 05:05:56PM +0300, Victor Krapivensky wrote:
> This change decouples waiting for next event from reacting to it. This
> makes the control flow easier to understand, and serves as a preparation
> for implementing a pull-style API for LuaJIT.
> 
> * strace.c (enum trace_event): New enum.
> (trace): Split into...
> (next_event, dispatch_event): ...new functions.
> (main): Use them.

Thanks, I merged this as you've probably noticed already.

> ---
>  strace.c | 351 ++++++++++++++++++++++++++++++++++++++-------------------------
>  1 file changed, 211 insertions(+), 140 deletions(-)
> 
> diff --git a/strace.c b/strace.c
> index 42650ab..0d3c8e9 100644
> --- a/strace.c
> +++ b/strace.c
> @@ -2252,21 +2252,76 @@ print_event_exit(struct tcb *tcp)
>  	line_ended();
>  }
>  
> -/* Returns true iff the main trace loop has to continue. */
> -static bool
> -trace(void)
> +enum trace_event {
> +	/* Break the main loop. */
> +	TE_BREAK,
> +
> +	/* Call next_event() again. */
> +	TE_NEXT,
> +
> +	/* Restart the tracee with signal 0 and call next_event() again. */
> +	TE_RESTART,
> +
> +	/*
> +	 * For all the events below, current_tcp is set to current tracee's tcb.
> +	 * All the suggested actions imply that you want to continue the tracing of the current
> +	 * tracee; alternatively, you can detach it.
> +	 */
> +
> +	/*
> +	 * Syscall entry or exit.
> +	 * Restart the tracee with signal 0, or with an injected signal number.
> +	 */
> +	TE_SYSCALL_STOP,
> +
> +	/*
> +	 * Tracee received signal with number WSTOPSIG(*pstatus); signal info is written to *si.
> +	 * Restart the tracee (with that signal number if you want to deliver it).
> +	 */
> +	TE_SIGNAL_DELIVERY_STOP,

Some of these comments needed a wrap so I did it.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170604/d996b53e/attachment.bin>


More information about the Strace-devel mailing list