2012-08-31 10:29:26 +02:00
|
|
|
#include <libunwind.h>
|
2002-11-09 04:59:27 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-08-31 10:29:26 +02:00
|
|
|
int ok;
|
|
|
|
int verbose;
|
2002-11-09 04:59:27 +01:00
|
|
|
|
2012-08-31 10:29:26 +02:00
|
|
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 3)
|
|
|
|
void a (int, ...) __attribute__((noinline, optimize(0)));
|
|
|
|
void b (void) __attribute__((noinline, optimize(0)));
|
|
|
|
void c (void) __attribute__((noinline, optimize(0)));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2002-11-09 04:59:27 +01:00
|
|
|
b (void)
|
|
|
|
{
|
|
|
|
void *v[20];
|
|
|
|
int i, n;
|
|
|
|
|
2012-08-31 10:29:26 +02:00
|
|
|
n = unw_backtrace(v, 20);
|
|
|
|
|
|
|
|
/* Check that the number of addresses given by unw_backtrace() looks
|
|
|
|
* reasonable. If the compiler inlined everything, then this check will also
|
|
|
|
* break. */
|
|
|
|
if (n >= 7)
|
|
|
|
ok = 1;
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
printf ("[%d] %p\n", i, v[i]);
|
2002-11-09 04:59:27 +01:00
|
|
|
}
|
|
|
|
|
2012-08-31 10:29:26 +02:00
|
|
|
void
|
2002-11-09 04:59:27 +01:00
|
|
|
c (void)
|
|
|
|
{
|
|
|
|
b ();
|
|
|
|
}
|
|
|
|
|
2012-08-31 10:29:26 +02:00
|
|
|
void
|
2002-11-09 04:59:27 +01:00
|
|
|
a (int d, ...)
|
|
|
|
{
|
|
|
|
switch (d)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
a (4, 2,4);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
a (3, 1,3,5);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
a (2, 11, 13, 17, 23);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
a (1);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
c ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-08-31 10:29:26 +02:00
|
|
|
main (int argc, char **argv __attribute__((unused)))
|
2002-11-09 04:59:27 +01:00
|
|
|
{
|
2012-08-31 10:29:26 +02:00
|
|
|
if (argc > 1)
|
|
|
|
verbose = 1;
|
|
|
|
|
2002-11-09 04:59:27 +01:00
|
|
|
a (5, 3, 4, 5, 6);
|
2012-08-31 10:29:26 +02:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "FAILURE: expected deeper backtrace.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
printf ("SUCCESS.\n");
|
|
|
|
|
2002-11-09 04:59:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|