[CRIU] [RFC] debug: add debug_wait to wait on signal

Dmitry Safonov dsafonov at odin.com
Thu Dec 24 08:54:36 PST 2015


On 12/24/2015 07:50 PM, Dmitry Safonov wrote:
> Currently to debug CRIU problems there is need sometimes to stop
> C/R processing and let computer operator to see what have happened.
> I.e, to see mount state in the middle of CR process, before error
> happens.
> So, people use sleep() and send SIGSTOP with ^Z, then do debug.
> It's working, but yet not very handy.
> If you want to find where problem first occurs, you need to place
> sleeps "here, there and everywhere". And each time rebuild CRIU.
> I suggest debug_wait() for this purpose.
> All normal people may use gdb breakpoints for this achievement,
> but as CRIU uses ptrace - it's no good for debugging it.
>
> Here is an example, how it works:
> 1. Placing debug_wait(SIGUSR1, "mount %s\n", mnt_path); on interested
> places in mount.c; (don't forget include debug.h)
> 2. Run CRUI and open restore.log to see the next line:
> (43.621767)      1: Warn  (mount.c:2394): mnt: debug_wait(-10): mount /tmp/cr-tmpfs.hu9dyJ
> 3. Send SIGUSR1 to restore process and continue debugging, looking in
> the log or fetching filesystem/other interesting source.
>
> Note: this patch is RFC, so I may move debug_wait_on() realization to
> debug.c, printing format or anything else if this debugging approach
> fits CRIU.
Side note, I forgot to mention: recently added CRIU timeout,
so you may want to disable/set to huge value as it will interrupt
your debug process.
>
> Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
> ---
>   include/debug.h | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
>   create mode 100644 include/debug.h
>
> diff --git a/include/debug.h b/include/debug.h
> new file mode 100644
> index 0000000..9ef671c
> --- /dev/null
> +++ b/include/debug.h
> @@ -0,0 +1,30 @@
> +#ifndef __CR_DEBUG_H__
> +#define __CR_DEBUG_H__
> +
> +#include <signal.h>
> +#include "criu-log.h"
> +
> +#define debug_wait(signum, reason, ...)                                        \
> +       pr_warn("debug_wait(-%d): " reason, signum, ##__VA_ARGS__);     \
> +       debug_wait_on(signum);
> +
> +static void __nop_handle(int signr) {}
> +
> +static inline void debug_wait_on(int signum)
> +{
> +       sigset_t mask;
> +       struct sigaction old_sigaction;
> +       struct sigaction new_sigaction = {
> +               .sa_handler = __nop_handle
> +       };
> +
> +       sigfillset(&mask);
> +       sigdelset(&mask, signum);
> +       sigaction(signum, &new_sigaction, &old_sigaction);
> +
> +       sigsuspend(&mask);
> +
> +       sigaction(signum, &old_sigaction, NULL);
> +}
> +
> +#endif /*  __CR_DEBUG_H__ */


-- 
Regards,
Dmitry Safonov



More information about the CRIU mailing list