Skip to content

Commit

Permalink
src: implement per-process native Debug() printer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung authored and MylesBorins committed Mar 10, 2020
1 parent 5127c70 commit 6aa797b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/debug_utils-inl.h
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/debug_utils.cc
Expand Up @@ -54,6 +54,9 @@
#endif // _WIN32

namespace node {
namespace per_process {
EnabledDebugList enabled_debug_list;
}

void EnabledDebugList::Parse(Environment* env) {
std::string cats;
Expand Down
10 changes: 10 additions & 0 deletions src/debug_utils.h
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/node.cc
Expand Up @@ -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();

Expand Down

0 comments on commit 6aa797b

Please sign in to comment.