4
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
5
6
6
#include " async_wrap.h"
7
- #include " env.h"
8
7
9
8
#include < sstream>
10
9
#include < string>
21
20
#endif
22
21
23
22
namespace node {
23
+ class Environment ;
24
24
25
25
template <typename T>
26
26
inline std::string ToString (const T& value);
@@ -36,31 +36,71 @@ template <typename... Args>
36
36
inline void FPrintF (FILE* file, const char * format, Args&&... args);
37
37
void FWrite (FILE* file, const std::string& str);
38
38
39
+ // Listing the AsyncWrap provider types first enables us to cast directly
40
+ // from a provider type to a debug category.
41
+ #define DEBUG_CATEGORY_NAMES (V ) \
42
+ NODE_ASYNC_PROVIDER_TYPES (V) \
43
+ V (INSPECTOR_SERVER) \
44
+ V (INSPECTOR_PROFILER) \
45
+ V (WASI)
46
+
47
+ enum class DebugCategory {
48
+ #define V (name ) name,
49
+ DEBUG_CATEGORY_NAMES (V)
50
+ #undef V
51
+ CATEGORY_COUNT
52
+ };
53
+
54
+ class EnabledDebugList {
55
+ public:
56
+ bool enabled (DebugCategory category) const {
57
+ DCHECK_GE (static_cast <int >(category), 0 );
58
+ DCHECK_LT (static_cast <int >(category),
59
+ static_cast <int >(DebugCategory::CATEGORY_COUNT));
60
+ return enabled_[static_cast <int >(category)];
61
+ }
62
+
63
+ // Uses NODE_DEBUG_NATIVE to initialize the categories. When env is not a
64
+ // nullptr, the environment variables set in the Environment are used.
65
+ // Otherwise the system environment variables are used.
66
+ void Parse (Environment* env);
67
+
68
+ private:
69
+ // Set all categories matching cats to the value of enabled.
70
+ void Parse (const std::string& cats, bool enabled);
71
+ void set_enabled (DebugCategory category, bool enabled) {
72
+ DCHECK_GE (static_cast <int >(category), 0 );
73
+ DCHECK_LT (static_cast <int >(category),
74
+ static_cast <int >(DebugCategory::CATEGORY_COUNT));
75
+ enabled_[static_cast <int >(category)] = true ;
76
+ }
77
+
78
+ bool enabled_[static_cast <int >(DebugCategory::CATEGORY_COUNT)] = {false };
79
+ };
80
+
39
81
template <typename ... Args>
40
- inline void FORCE_INLINE Debug (Environment* env ,
82
+ inline void FORCE_INLINE Debug (EnabledDebugList* list ,
41
83
DebugCategory cat,
42
84
const char * format,
43
- Args&&... args) {
44
- if (!UNLIKELY (env->debug_enabled (cat)))
45
- return ;
46
- FPrintF (stderr, format, std::forward<Args>(args)...);
47
- }
85
+ Args&&... args);
86
+
87
+ inline void FORCE_INLINE Debug (EnabledDebugList* list,
88
+ DebugCategory cat,
89
+ const char * message);
90
+
91
+ template <typename ... Args>
92
+ inline void FORCE_INLINE
93
+ Debug (Environment* env, DebugCategory cat, const char * format, Args&&... args);
48
94
49
95
inline void FORCE_INLINE Debug (Environment* env,
50
96
DebugCategory cat,
51
- const char * message) {
52
- if (!UNLIKELY (env->debug_enabled (cat)))
53
- return ;
54
- FPrintF (stderr, " %s" , message);
55
- }
97
+ const char * message);
56
98
57
99
template <typename ... Args>
58
100
inline void Debug (Environment* env,
59
101
DebugCategory cat,
60
102
const std::string& format,
61
- Args&&... args) {
62
- Debug (env, cat, format.c_str (), std::forward<Args>(args)...);
63
- }
103
+ Args&&... args);
64
104
65
105
// Used internally by the 'real' Debug(AsyncWrap*, ...) functions below, so that
66
106
// the FORCE_INLINE flag on them doesn't apply to the contents of this function
@@ -72,31 +112,17 @@ inline void Debug(Environment* env,
72
112
template <typename ... Args>
73
113
void COLD_NOINLINE UnconditionalAsyncWrapDebug (AsyncWrap* async_wrap,
74
114
const char * format,
75
- Args&&... args) {
76
- Debug (async_wrap->env (),
77
- static_cast <DebugCategory>(async_wrap->provider_type ()),
78
- async_wrap->diagnostic_name () + " " + format + " \n " ,
79
- std::forward<Args>(args)...);
80
- }
115
+ Args&&... args);
81
116
82
117
template <typename ... Args>
83
118
inline void FORCE_INLINE Debug (AsyncWrap* async_wrap,
84
119
const char * format,
85
- Args&&... args) {
86
- DCHECK_NOT_NULL (async_wrap);
87
- DebugCategory cat =
88
- static_cast <DebugCategory>(async_wrap->provider_type ());
89
- if (!UNLIKELY (async_wrap->env ()->debug_enabled (cat)))
90
- return ;
91
- UnconditionalAsyncWrapDebug (async_wrap, format, std::forward<Args>(args)...);
92
- }
120
+ Args&&... args);
93
121
94
122
template <typename ... Args>
95
123
inline void FORCE_INLINE Debug (AsyncWrap* async_wrap,
96
124
const std::string& format,
97
- Args&&... args) {
98
- Debug (async_wrap, format.c_str (), std::forward<Args>(args)...);
99
- }
125
+ Args&&... args);
100
126
101
127
// Debug helper for inspecting the currently running `node` executable.
102
128
class NativeSymbolDebuggingContext {
0 commit comments