1 /* 2 * Backtrace debugging 3 * Copyright (c) 2009, Jouni Malinen <j (at) 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 44 #else /* WPA_TRACE */ 45 46 #define WPA_TRACE_INFO 47 #define WPA_TRACE_REF(n) 48 #define wpa_trace_dump(title, ptr) do { } while (0) 49 #define wpa_trace_record(ptr) do { } while (0) 50 #define wpa_trace_show(title) do { } while (0) 51 #define wpa_trace_add_ref(ptr, name, addr) do { } while (0) 52 #define wpa_trace_remove_ref(ptr, name, addr) do { } while (0) 53 #define wpa_trace_check_ref(addr) do { } while (0) 54 55 #endif /* WPA_TRACE */ 56 57 58 #ifdef WPA_TRACE_BFD 59 60 void wpa_trace_dump_funcname(const char *title, void *pc); 61 62 #else /* WPA_TRACE_BFD */ 63 64 #define wpa_trace_dump_funcname(title, pc) do { } while (0) 65 66 #endif /* WPA_TRACE_BFD */ 67 68 #endif /* TRACE_H */ 69