[Spice-devel] [PATCH] common: add backtrace via gstack

Uri Lublin uril at redhat.com
Thu Jul 14 01:53:30 PDT 2011


On 07/14/2011 10:50 AM, Alon Levy wrote:
> Add a backtrace printing function copied from xserver os/backtrace.c
> that uses gstack which seems to be available enough that xserver uses it :)
> Used in ASSERT, tested on F15.
> ---
> diff --git a/common/backtrace.c b/common/backtrace.c
> +
> +        while (!done) {
> +            bytesread = read(pipefd[0], btline, sizeof(btline) - 1);
> +
> +            if (bytesread>  0) {
> +                btline[bytesread] = 0;
> +                red_printf("%s", btline);

nitpick: why not just printf similarly to ASSERT below ?

> +            }
> +            else if ((bytesread<  0) ||
> +                     ((errno != EINTR)&&  (errno != EAGAIN)))
> +                done = 1;

This seems wrong. If read() fails due to EINTR or EAGAIN this condition breaks 
out of the while loop.
I think it should be
     ((bytesread < 0) && (errno != EINTR) && (errno != EAGAIN))

or (break when read() returns the value 0 -- end of file)
     ((bytesread == 0) || ((errno != EINTR)&&  (errno != EAGAIN)))

> +        }
> diff --git a/common/spice_common.h b/common/spice_common.h
>
>   #define ASSERT(x) if (!(x)) {                               \
>       printf("%s: ASSERT %s failed\n", __FUNCTION__, #x);     \
> +    backtrace();                                           \
>       abort();                                                \
>   }
>



More information about the Spice-devel mailing list