summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2020-02-20 17:22:48 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2020-03-10 05:52:38 +0800
commit51bc55f2a2424d6eb805dace43604906ed9946a8 (patch)
tree1e704a8afdf533d05332ed82c013839e59828cef
parenta8772da54dd8ccc658cf56992b2ba46a021f6e83 (diff)
downloadnode-new-51bc55f2a2424d6eb805dace43604906ed9946a8.tar.gz
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 <anna@addaleax.net>
-rw-r--r--src/debug_utils-inl.h14
-rw-r--r--src/debug_utils.cc3
-rw-r--r--src/debug_utils.h10
-rw-r--r--src/node.cc4
4 files changed, 31 insertions, 0 deletions
diff --git a/src/debug_utils-inl.h b/src/debug_utils-inl.h
index 5593957c5b..ae2d204648 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>(args)...);
}
+namespace per_process {
+
+template <typename... Args>
+inline void FORCE_INLINE Debug(DebugCategory cat,
+ const char* format,
+ Args&&... args) {
+ Debug(&enabled_debug_list, cat, format, std::forward<Args>(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 0f25a70e78..a601c5ecf4 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 527e3549fa..200f1cf07c 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 <typename... Args>
+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 6b95796e12..1fec85aa79 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();