summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/utils/test/TestBacktrace.c
blob: 5fea333ecd518cef79a72e30401d5d15501b743f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <winpr/debug.h>

int TestBacktrace(int argc, char* argv[])
{
	int rc = -1;
	size_t used = 0;
	char** msg = NULL;
	void* stack = winpr_backtrace(20);

	WINPR_UNUSED(argc);
	WINPR_UNUSED(argv);

	if (!stack)
	{
		fprintf(stderr, "winpr_backtrace failed!\n");
		return -1;
	}

	msg = winpr_backtrace_symbols(stack, &used);

	if (msg)
	{
		for (size_t x = 0; x < used; x++)
			printf("%" PRIuz ": %s\n", x, msg[x]);

		rc = 0;
	}

	winpr_backtrace_symbols_fd(stack, fileno(stdout));
	winpr_backtrace_free(stack);
	free(msg);
	return rc;
}