Add backtrace support for debugging
[libeap.git] / src / utils / trace.c
1 /*
2  * Backtrace debugging
3  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "includes.h"
16
17 #include "common.h"
18 #include "trace.h"
19
20 #ifdef WPA_TRACE
21
22 void wpa_trace_dump_func(const char *title, void **btrace, int btrace_num)
23 {
24         char **sym;
25         int i;
26
27         wpa_printf(MSG_INFO, "WPA_TRACE: %s - START", title);
28         sym = backtrace_symbols(btrace, btrace_num);
29         for (i = 0; i < btrace_num; i++)
30                 wpa_printf(MSG_INFO, "[%d]: %p: %s",
31                            i, btrace[i], sym ? sym[i] : "");
32         os_free(sym);
33         wpa_printf(MSG_INFO, "WPA_TRACE: %s - END", title);
34 }
35
36
37 void wpa_trace_show(const char *title)
38 {
39         struct info {
40                 WPA_TRACE_INFO
41         } info;
42         wpa_trace_record(&info);
43         wpa_trace_dump(title, &info);
44 }
45
46 #endif /* WPA_TRACE */