#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "libunwind.h"
static const char* other_expected[] = { "bar", "foo", "work", "_pthread_start", NULL, NULL };
static const char* main_expected[] = { "bar", "foo", "main", NULL, NULL };
extern int foo(const char** list);
int bar(const char** list)
{
char functionName[64];
unw_cursor_t cursor;
unw_context_t uc;
unw_word_t offset;
int index = 0;
unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
do {
unw_get_proc_name(&cursor, functionName, 64, &offset);
if ( (list[index] != NULL) && (strcmp(functionName, list[index]) != 0) ) {
exit(1);
}
++index;
} while (unw_step(&cursor) > 0);
return 0;
}
static void* work(void* arg)
{
foo((const char**)arg);
return NULL;
}
int main()
{
pthread_t worker1;
if ( pthread_create(&worker1, NULL, work, other_expected) != 0 ) {
exit(0);
}
void* result;
pthread_join(worker1, &result);
return foo(main_expected);
}