Skip to content

Commit f965d73

Browse files
joyeecheungcodebytere
authored andcommitted
src: implement per-process native Debug() printer
This patch adds a per-process native Debug() printer that can be called when an Environment is not available. PR-URL: #31884 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 3fe3fa2 commit f965d73

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/debug_utils-inl.h

+14
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
164164
Debug(async_wrap, format.c_str(), std::forward<Args>(args)...);
165165
}
166166

167+
namespace per_process {
168+
169+
template <typename... Args>
170+
inline void FORCE_INLINE Debug(DebugCategory cat,
171+
const char* format,
172+
Args&&... args) {
173+
Debug(&enabled_debug_list, cat, format, std::forward<Args>(args)...);
174+
}
175+
176+
inline void FORCE_INLINE Debug(DebugCategory cat, const char* message) {
177+
Debug(&enabled_debug_list, cat, message);
178+
}
179+
180+
} // namespace per_process
167181
} // namespace node
168182

169183
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/debug_utils.cc

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
#endif // _WIN32
5555

5656
namespace node {
57+
namespace per_process {
58+
EnabledDebugList enabled_debug_list;
59+
}
5760

5861
void EnabledDebugList::Parse(Environment* env) {
5962
std::string cats;

src/debug_utils.h

+10
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ class NativeSymbolDebuggingContext {
161161
void CheckedUvLoopClose(uv_loop_t* loop);
162162
void PrintLibuvHandleInformation(uv_loop_t* loop, FILE* stream);
163163

164+
namespace per_process {
165+
extern EnabledDebugList enabled_debug_list;
166+
167+
template <typename... Args>
168+
inline void FORCE_INLINE Debug(DebugCategory cat,
169+
const char* format,
170+
Args&&... args);
171+
172+
inline void FORCE_INLINE Debug(DebugCategory cat, const char* message);
173+
} // namespace per_process
164174
} // namespace node
165175

166176
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/node.cc

+4
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ void Init(int* argc,
862862
}
863863

864864
InitializationResult InitializeOncePerProcess(int argc, char** argv) {
865+
// Initialized the enabled list for Debug() calls with system
866+
// environment variables.
867+
per_process::enabled_debug_list.Parse(nullptr);
868+
865869
atexit(ResetStdio);
866870
PlatformInit();
867871

0 commit comments

Comments
 (0)