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 #ifndef TRACE_H 16 #define TRACE_H 17 18 #define WPA_TRACE_LEN 16 19 20 #ifdef WPA_TRACE 21 #include <execinfo.h> 22 23 #include "list.h" 24 25 #define WPA_TRACE_INFO void *btrace[WPA_TRACE_LEN]; int btrace_num; 26 27 struct wpa_trace_ref { 28 struct dl_list list; 29 const void *addr; 30 WPA_TRACE_INFO 31 }; 32 #define WPA_TRACE_REF(name) struct wpa_trace_ref wpa_trace_ref_##name 33 34 #define wpa_trace_dump(title, ptr) \ 35 wpa_trace_dump_func((title), (ptr)->btrace, (ptr)->btrace_num) 36 void wpa_trace_dump_func(const char *title, void **btrace, int btrace_num); 37 #define wpa_trace_record(ptr) \ 38 (ptr)->btrace_num = backtrace((ptr)->btrace, WPA_TRACE_LEN) 39 void wpa_trace_show(const char *title); 40 #define wpa_trace_add_ref(ptr, name, addr) \ 41 wpa_trace_add_ref_func(&(ptr)->wpa_trace_ref_##name, (addr)) 42 void wpa_trace_add_ref_func(struct wpa_trace_ref *ref, const void *addr); 43 #define wpa_trace_remove_ref(ptr, name, addr) \ 44 do { \ 45 if ((addr)) \ 46 dl_list_del(&(ptr)->wpa_trace_ref_##name.list); \ 47 } while (0) 48 void wpa_trace_check_ref(const void *addr); 49 50 #else /* WPA_TRACE */ 51 52 #define WPA_TRACE_INFO 53 #define WPA_TRACE_REF(n) 54 #define wpa_trace_dump(title, ptr) do { } while (0) 55 #define wpa_trace_record(ptr) do { } while (0) 56 #define wpa_trace_show(title) do { } while (0) 57 #define wpa_trace_add_ref(ptr, name, addr) do { } while (0) 58 #define wpa_trace_remove_ref(ptr, name, addr) do { } while (0) 59 #define wpa_trace_check_ref(addr) do { } while (0) 60 61 #endif /* WPA_TRACE */ 62 63 64 #ifdef WPA_TRACE_BFD 65 66 void wpa_trace_dump_funcname(const char *title, void *pc); 67 68 #else /* WPA_TRACE_BFD */ 69 70 #define wpa_trace_dump_funcname(title, pc) do { } while (0) 71 72 #endif /* WPA_TRACE_BFD */ 73 74 #endif /* TRACE_H */ 75