xref: /freebsd/contrib/wpa/src/utils/trace.h (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
1 /*
2  * Backtrace debugging
3  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef TRACE_H
10 #define TRACE_H
11 
12 #define WPA_TRACE_LEN 16
13 
14 #ifdef WPA_TRACE
15 #include <execinfo.h>
16 
17 #include "list.h"
18 
19 #define WPA_TRACE_INFO void *btrace[WPA_TRACE_LEN]; int btrace_num;
20 
21 struct wpa_trace_ref {
22 	struct dl_list list;
23 	const void *addr;
24 	WPA_TRACE_INFO
25 };
26 #define WPA_TRACE_REF(name) struct wpa_trace_ref wpa_trace_ref_##name
27 
28 #define wpa_trace_dump(title, ptr) \
29 	wpa_trace_dump_func((title), (ptr)->btrace, (ptr)->btrace_num)
30 void wpa_trace_dump_func(const char *title, void **btrace, int btrace_num);
31 #define wpa_trace_record(ptr) \
32 	(ptr)->btrace_num = backtrace((ptr)->btrace, WPA_TRACE_LEN)
33 void wpa_trace_show(const char *title);
34 #define wpa_trace_add_ref(ptr, name, addr) \
35 	wpa_trace_add_ref_func(&(ptr)->wpa_trace_ref_##name, (addr))
36 void wpa_trace_add_ref_func(struct wpa_trace_ref *ref, const void *addr);
37 #define wpa_trace_remove_ref(ptr, name, addr)	\
38 	do { \
39 		if ((addr)) \
40 			dl_list_del(&(ptr)->wpa_trace_ref_##name.list); \
41 	} while (0)
42 void wpa_trace_check_ref(const void *addr);
43 size_t wpa_trace_calling_func(const char *buf[], size_t len);
44 
45 #else /* WPA_TRACE */
46 
47 #define WPA_TRACE_INFO
48 #define WPA_TRACE_REF(n)
49 #define wpa_trace_dump(title, ptr) do { } while (0)
50 #define wpa_trace_record(ptr) do { } while (0)
51 #define wpa_trace_show(title) do { } while (0)
52 #define wpa_trace_add_ref(ptr, name, addr) do { } while (0)
53 #define wpa_trace_remove_ref(ptr, name, addr) do { } while (0)
54 #define wpa_trace_check_ref(addr) do { } while (0)
55 
56 #endif /* WPA_TRACE */
57 
58 
59 #ifdef WPA_TRACE_BFD
60 
61 void wpa_trace_dump_funcname(const char *title, void *pc);
62 
63 #else /* WPA_TRACE_BFD */
64 
65 #define wpa_trace_dump_funcname(title, pc) do { } while (0)
66 
67 #endif /* WPA_TRACE_BFD */
68 
69 void wpa_trace_deinit(void);
70 
71 #endif /* TRACE_H */
72