#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace ()
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size
);
for (i = 0; i < size; i++)
}
/* A dummy function to make the backtrace more interesting. */
void
dummy_function (int i)
{
(void)i;
print_trace ();
}
int
main (void)
{
int i = (int)&main - (int)&dummy_function + (int)&main - (int)&print_trace;
dummy_function (i);
return 0;
}
ICAgICAjaW5jbHVkZSA8ZXhlY2luZm8uaD4KICAgICAjaW5jbHVkZSA8c3RkaW8uaD4KICAgICAjaW5jbHVkZSA8c3RkbGliLmg+CiAgICAgCiAgICAgLyogT2J0YWluIGEgYmFja3RyYWNlIGFuZCBwcmludCBpdCB0byBzdGRvdXQuICovCiAgICAgdm9pZAogICAgIHByaW50X3RyYWNlICgpCiAgICAgewogICAgICAgdm9pZCAqYXJyYXlbMTBdOwogICAgICAgc2l6ZV90IHNpemU7CiAgICAgICBjaGFyICoqc3RyaW5nczsKICAgICAgIHNpemVfdCBpOwogICAgIAogICAgICAgc2l6ZSA9IGJhY2t0cmFjZSAoYXJyYXksIDEwKTsKICAgICAgIHN0cmluZ3MgPSBiYWNrdHJhY2Vfc3ltYm9scyAoYXJyYXksIHNpemUpOwogICAgIAogICAgICAgcHJpbnRmICgiT2J0YWluZWQgJXpkIHN0YWNrIGZyYW1lcy5cbiIsIHNpemUpOwogICAgIAogICAgICAgZm9yIChpID0gMDsgaSA8IHNpemU7IGkrKykKICAgICAgICAgIHByaW50ZiAoIiVzXG4iLCBzdHJpbmdzW2ldKTsKICAgICAKICAgICAgIGZyZWUgKHN0cmluZ3MpOwogICAgIH0KICAgICAKICAgICAvKiBBIGR1bW15IGZ1bmN0aW9uIHRvIG1ha2UgdGhlIGJhY2t0cmFjZSBtb3JlIGludGVyZXN0aW5nLiAqLwogICAgIHZvaWQKICAgICBkdW1teV9mdW5jdGlvbiAoaW50IGkpCiAgICAgewogICAgICAgKHZvaWQpaTsKICAgICAgIHByaW50X3RyYWNlICgpOwogICAgIH0KICAgICAKICAgICBpbnQKICAgICBtYWluICh2b2lkKQogICAgIHsKICAgICAgIGludCBpID0gKGludCkmbWFpbiAtIChpbnQpJmR1bW15X2Z1bmN0aW9uICsgKGludCkmbWFpbiAtIChpbnQpJnByaW50X3RyYWNlOwogICAgICAgZHVtbXlfZnVuY3Rpb24gKGkpOwogICAgICAgcmV0dXJuIDA7CiAgICAgfQ==