trace.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef TRACE_H
  9. #define TRACE_H
  10. #define FOTA_TRACE_LEN 16
  11. #ifdef FOTA_TRACE
  12. #include <execinfo.h>
  13. #include "list.h"
  14. #define FOTA_TRACE_INFO void *btrace[FOTA_TRACE_LEN]; int btrace_num;
  15. struct fota_trace_ref {
  16. struct dl_list list;
  17. const void *addr;
  18. FOTA_TRACE_INFO
  19. };
  20. #define FOTA_TRACE_REF(name) struct fota_trace_ref fota_trace_ref_##name
  21. #define fota_trace_dump(title, ptr) \
  22. fota_trace_dump_func((title), (ptr)->btrace, (ptr)->btrace_num)
  23. void fota_trace_dump_func(const char *title, void **btrace, int btrace_num);
  24. #define fota_trace_record(ptr) \
  25. (ptr)->btrace_num = backtrace((ptr)->btrace, FOTA_TRACE_LEN)
  26. void fota_trace_show(const char *title);
  27. #define fota_trace_add_ref(ptr, name, addr) \
  28. fota_trace_add_ref_func(&(ptr)->fota_trace_ref_##name, (addr))
  29. void fota_trace_add_ref_func(struct fota_trace_ref *ref, const void *addr);
  30. #define fota_trace_remove_ref(ptr, name, addr) \
  31. do { \
  32. if ((addr)) \
  33. dl_list_del(&(ptr)->fota_trace_ref_##name.list); \
  34. } while (0)
  35. void fota_trace_check_ref(const void *addr);
  36. size_t fota_trace_calling_func(const char *buf[], size_t len);
  37. #else /* FOTA_TRACE */
  38. #define FOTA_TRACE_INFO
  39. #define FOTA_TRACE_REF(n)
  40. #define fota_trace_dump(title, ptr) do { } while (0)
  41. #define fota_trace_record(ptr) do { } while (0)
  42. #define fota_trace_show(title) do { } while (0)
  43. #define fota_trace_add_ref(ptr, name, addr) do { } while (0)
  44. #define fota_trace_remove_ref(ptr, name, addr) do { } while (0)
  45. #define fota_trace_check_ref(addr) do { } while (0)
  46. #endif /* FOTA_TRACE */
  47. #ifdef FOTA_TRACE_BFD
  48. void fota_trace_dump_funcname(const char *title, void *pc);
  49. #else /* FOTA_TRACE_BFD */
  50. #define fota_trace_dump_funcname(title, pc) do { } while (0)
  51. #endif /* FOTA_TRACE_BFD */
  52. void fota_trace_deinit(void);
  53. #endif /* TRACE_H */