From 6aa797b5466bd3a6a326ff3f98862de16355a7da Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 20 Feb 2020 17:22:48 +0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/31884 Reviewed-By: Anna Henningsen --- src/debug_utils-inl.h | 14 ++++++++++++++ src/debug_utils.cc | 3 +++ src/debug_utils.h | 10 ++++++++++ src/node.cc | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/src/debug_utils-inl.h b/src/debug_utils-inl.h index 5593957c5b2c6b..ae2d2046486466 100644 --- a/src/debug_utils-inl.h +++ b/src/debug_utils-inl.h @@ -164,6 +164,20 @@ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap, Debug(async_wrap, format.c_str(), std::forward(args)...); } +namespace per_process { + +template +inline void FORCE_INLINE Debug(DebugCategory cat, + const char* format, + Args&&... args) { + Debug(&enabled_debug_list, cat, format, std::forward(args)...); +} + +inline void FORCE_INLINE Debug(DebugCategory cat, const char* message) { + Debug(&enabled_debug_list, cat, message); +} + +} // namespace per_process } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/debug_utils.cc b/src/debug_utils.cc index 0f25a70e787bce..a601c5ecf40ea9 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -54,6 +54,9 @@ #endif // _WIN32 namespace node { +namespace per_process { +EnabledDebugList enabled_debug_list; +} void EnabledDebugList::Parse(Environment* env) { std::string cats; diff --git a/src/debug_utils.h b/src/debug_utils.h index 527e3549fa0e43..200f1cf07cd27b 100644 --- a/src/debug_utils.h +++ b/src/debug_utils.h @@ -161,6 +161,16 @@ class NativeSymbolDebuggingContext { void CheckedUvLoopClose(uv_loop_t* loop); void PrintLibuvHandleInformation(uv_loop_t* loop, FILE* stream); +namespace per_process { +extern EnabledDebugList enabled_debug_list; + +template +inline void FORCE_INLINE Debug(DebugCategory cat, + const char* format, + Args&&... args); + +inline void FORCE_INLINE Debug(DebugCategory cat, const char* message); +} // namespace per_process } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/node.cc b/src/node.cc index 6b95796e1269b3..1fec85aa793dc4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -916,6 +916,10 @@ void Init(int* argc, } InitializationResult InitializeOncePerProcess(int argc, char** argv) { + // Initialized the enabled list for Debug() calls with system + // environment variables. + per_process::enabled_debug_list.Parse(nullptr); + atexit(ResetStdio); PlatformInit();