|
26 | 26 | #ifndef FIRMWARE_DEBUG_DEBUG_H_ |
27 | 27 | #define FIRMWARE_DEBUG_DEBUG_H_ |
28 | 28 |
|
29 | | -#if !defined(NDEBUG) |
30 | 29 | #include <cstdio> |
31 | 30 | #include <source_location> |
32 | 31 |
|
33 | | -#define DEBUG_ENTRY() \ |
34 | | - do { \ |
35 | | - const std::source_location loc = std::source_location::current(); \ |
36 | | - printf("-> %s(%u):%s\n", loc.file_name(), static_cast<unsigned>(loc.line()), loc.function_name()); \ |
37 | | - } while (0) |
| 32 | +#include "firmware/debug/debug_config.h" |
38 | 33 |
|
39 | | -#define DEBUG_EXIT() \ |
40 | | - do { \ |
41 | | - const std::source_location loc = std::source_location::current(); \ |
42 | | - printf("<- %s(%u):%s\n", loc.file_name(), static_cast<unsigned>(loc.line()), loc.function_name()); \ |
43 | | - } while (0) |
| 34 | +#define DEBUG_ENTRY() \ |
| 35 | + do { \ |
| 36 | + if constexpr (::debug::config::kTraceEnabled) { \ |
| 37 | + const auto location = std::source_location::current(); \ |
| 38 | + printf("-> %s(%u):%s\n", \ |
| 39 | + location.file_name(), \ |
| 40 | + static_cast<unsigned>(location.line()), \ |
| 41 | + location.function_name()); \ |
| 42 | + } \ |
| 43 | + } while (false) |
44 | 44 |
|
45 | | -#define DEBUG_PRINTF(fmt, ...) \ |
46 | | - do { \ |
47 | | - const std::source_location loc = std::source_location::current(); \ |
48 | | - printf(" %s(%u):%s: " fmt "\n", loc.file_name(), static_cast<unsigned>(loc.line()), loc.function_name() __VA_OPT__(, ) __VA_ARGS__); \ |
49 | | - } while (0) |
| 45 | +#define DEBUG_EXIT() \ |
| 46 | + do { \ |
| 47 | + if constexpr (::debug::config::kTraceEnabled) { \ |
| 48 | + const auto location = std::source_location::current(); \ |
| 49 | + printf("<- %s(%u):%s\n", \ |
| 50 | + location.file_name(), \ |
| 51 | + static_cast<unsigned>(location.line()), \ |
| 52 | + location.function_name()); \ |
| 53 | + } \ |
| 54 | + } while (false) |
50 | 55 |
|
51 | | -#define DEBUG_PUTS(msg) \ |
52 | | - do { \ |
53 | | - DEBUG_PRINTF("%s", (msg)); \ |
54 | | - } while (0) |
| 56 | +#define DEBUG_PRINTF(format, ...) \ |
| 57 | + do { \ |
| 58 | + if constexpr (::debug::config::kTraceEnabled) { \ |
| 59 | + const auto location = std::source_location::current(); \ |
| 60 | + printf(" %s(%u):%s: " format "\n", \ |
| 61 | + location.file_name(), \ |
| 62 | + static_cast<unsigned>(location.line()), \ |
| 63 | + location.function_name() __VA_OPT__(, ) __VA_ARGS__); \ |
| 64 | + } \ |
| 65 | + } while (false) |
55 | 66 |
|
56 | | -#else |
57 | | - |
58 | | -#define DEBUG_ENTRY() \ |
59 | | - do { \ |
60 | | - } while (0) |
61 | | - |
62 | | -#define DEBUG_EXIT() \ |
63 | | - do { \ |
64 | | - } while (0) |
65 | | - |
66 | | -#define DEBUG_PRINTF(...) \ |
67 | | - do { \ |
68 | | - } while (0) |
69 | | - |
70 | | -#define DEBUG_PUTS(...) \ |
71 | | - do { \ |
72 | | - } while (0) |
73 | | - |
74 | | -#endif |
| 67 | +#define DEBUG_PUTS(message) \ |
| 68 | + do { \ |
| 69 | + DEBUG_PRINTF("%s", (message)); \ |
| 70 | + } while (false) |
75 | 71 |
|
76 | 72 | #endif // FIRMWARE_DEBUG_DEBUG_H_ |
0 commit comments