diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-05-27 16:37:30 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-05-31 09:54:48 +0200 |
commit | bd85844c4e80c7aa1fc02a986c7619c3956b0061 (patch) | |
tree | d476c4d0b3469dfee41913b9a76ff39ab1deabfe /src/env.cc | |
parent | eadcee11372d8228bcb203a9ab97a5f7d61d4809 (diff) | |
download | android-node-v8-bd85844c4e80c7aa1fc02a986c7619c3956b0061.tar.gz android-node-v8-bd85844c4e80c7aa1fc02a986c7619c3956b0061.tar.bz2 android-node-v8-bd85844c4e80c7aa1fc02a986c7619c3956b0061.zip |
src: implement debug output utilities
Implement utilities for easier debugging of Node.js core code,
inspired by the HTTP/2 debugging code. Debugging is, however,
implemented at runtime rather than at compile time, controlled
through a new `NODE_DEBUG_NATIVE=categories` environment variable.
The runtime overhead in the debugging-disabled case amounts to
1 well-cachable one-byte read per debug call.
PR-URL: https://github.com/nodejs/node/pull/20987
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc index 2fa4432c54..f6303e6011 100644 --- a/src/env.cc +++ b/src/env.cc @@ -130,6 +130,10 @@ Environment::Environment(IsolateData* isolate_data, // By default, always abort when --abort-on-uncaught-exception was passed. should_abort_on_uncaught_toggle_[0] = 1; + + std::string debug_cats; + SafeGetenv("NODE_DEBUG_NATIVE", &debug_cats); + set_debug_categories(debug_cats, true); } Environment::~Environment() { @@ -496,6 +500,28 @@ Local<Value> Environment::GetNow() { } +void Environment::set_debug_categories(const std::string& cats, bool enabled) { + std::string debug_categories = cats; + while (!debug_categories.empty()) { + std::string::size_type comma_pos = debug_categories.find(','); + std::string wanted = ToLower(debug_categories.substr(0, comma_pos)); + +#define V(name) \ + { \ + static const std::string available_category = ToLower(#name); \ + if (available_category.find(wanted) != std::string::npos) \ + set_debug_enabled(DebugCategory::name, enabled); \ + } + + DEBUG_CATEGORY_NAMES(V) + + if (comma_pos == std::string::npos) + break; + // Use everything after the `,` as the list for the next iteration. + debug_categories = debug_categories.substr(comma_pos); + } +} + void CollectExceptionInfo(Environment* env, v8::Local<v8::Object> obj, int errorno, |