1
2#include <stddef.h>
3#include <stdlib.h>
4#include <stdio.h>
5
6#include "libunwind.h"
7
8extern int unwind_tester(void*);
9extern void* unwind_tester_list[];
10
11int main()
12{
13	// loop over all function pointers in unwind_tester_list
14	// and call unwind_tester() on each one.  If it returns
15	// non-zero, then that test failed.
16	void** p;
17	for(p=unwind_tester_list; *p != NULL; ++p) {
18		//fprintf(stderr, "unwind_tester(%p)\n", *p);
19		if ( unwind_tester(*p) )
20			return 1;
21	}
22	return 0;
23}
24
25// called by test function
26// we unwind through the test function
27// and resume at caller (unwind_tester)
28void uwind_to_main()
29{
30	unw_cursor_t cursor;
31	unw_context_t uc;
32	unw_word_t	offset;
33
34	unw_getcontext(&uc);
35	unw_init_local(&cursor, &uc);
36	if ( unw_step(&cursor) > 0 ) {
37		// now in test function
38		if ( unw_step(&cursor) > 0 ) {
39			// now in unwind_tester
40			unw_resume(&cursor);
41		}
42	}
43	// error if we got here
44	exit(1);
45}
46
47