btrfs-progs-0001-add-option-to-disable-backtrace-usage.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From eb8d1bbdfea80a50ce9fbf3238062a543036f855 Mon Sep 17 00:00:00 2001
  2. From: Gustavo Zacarias <gustavo@zacarias.com.ar>
  3. Date: Tue, 7 Oct 2014 11:03:03 -0300
  4. Subject: [PATCH] btrfs-progs: add option to disable backtrace usage
  5. This commit adds the support for a make variable named
  6. "DISABLE_BACKTRACE" which allows to disable the support for backtrace()
  7. usage on ASSERT(), BUG() and BUG_ON() calls.
  8. This is useful because some alternative C libraries like uClibc have
  9. optional support for backtrace() which is rarely built when debugging
  10. isn't taking place.
  11. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
  12. ---
  13. Makefile | 4 ++++
  14. kerncompat.h | 15 +++++++++++++++
  15. 2 files changed, 19 insertions(+)
  16. diff --git a/Makefile b/Makefile
  17. index 7cc7783..03a4779 100644
  18. --- a/Makefile
  19. +++ b/Makefile
  20. @@ -63,6 +63,10 @@ BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
  21. INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
  22. CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
  23. +ifeq ($(DISABLE_BACKTRACE),1)
  24. +AM_CFLAGS += -DBTRFS_DISABLE_BACKTRACE
  25. +endif
  26. +
  27. ifneq ($(DISABLE_DOCUMENTATION),1)
  28. BUILDDIRS += build-Documentation
  29. INSTALLDIRS += install-Documentation
  30. diff --git a/kerncompat.h b/kerncompat.h
  31. index 19c7fa5..889d94c 100644
  32. --- a/kerncompat.h
  33. +++ b/kerncompat.h
  34. @@ -29,7 +29,9 @@
  35. #include <stddef.h>
  36. #include <linux/types.h>
  37. #include <stdint.h>
  38. +#ifndef BTRFS_DISABLE_BACKTRACE
  39. #include <execinfo.h>
  40. +#endif
  41. #define ptr_to_u64(x) ((u64)(uintptr_t)x)
  42. #define u64_to_ptr(x) ((void *)(uintptr_t)x)
  43. @@ -55,6 +57,7 @@
  44. #define ULONG_MAX (~0UL)
  45. #endif
  46. +#ifndef BTRFS_DISABLE_BACKTRACE
  47. #define MAX_BACKTRACE 16
  48. static inline void print_trace(void)
  49. {
  50. @@ -81,6 +84,9 @@ static inline void assert_trace(const char *assertion, const char *filename,
  51. }
  52. #define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0)
  53. +#else
  54. +#define BUG() assert(0)
  55. +#endif
  56. #ifdef __CHECKER__
  57. #define __force __attribute__((force))
  58. @@ -264,10 +270,19 @@ static inline long IS_ERR(const void *ptr)
  59. #define kstrdup(x, y) strdup(x)
  60. #define kfree(x) free(x)
  61. +#ifndef BTRFS_DISABLE_BACKTRACE
  62. #define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c))
  63. +#else
  64. +#define BUG_ON(c) assert(!(c))
  65. +#endif
  66. #define WARN_ON(c) BUG_ON(c)
  67. +
  68. +#ifndef BTRFS_DISABLE_BACKTRACE
  69. #define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c))
  70. +#else
  71. +#define ASSERT(c) assert(c)
  72. +#endif
  73. #define container_of(ptr, type, member) ({ \
  74. const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  75. --
  76. 2.0.4