diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 99a0f676ed..30f0d8cdd0 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -24,6 +24,7 @@ #include #include +#include #include @@ -113,6 +114,30 @@ UniValue getinfo(const UniValue& params, bool fHelp) return obj; } +UniValue debug(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debug ( 0|1|addrman|alert|bench|coindb|db|lock|rand|rpc|selectcoins|mempool" + "|mempoolrej|net|proxy|prune|http|libevent|tor|zmq|" + "dash|darksend|instantx|masternode|keepass|mnpayments|mnbudget )\n" + "Change debug category on the fly. Specify single category or use comma to specify many.\n" + "\nExamples:\n" + + HelpExampleCli("debug", "dash") + + HelpExampleRpc("debug", "dash,net") + ); + + std::string strMode = params[0].get_str(); + + mapMultiArgs["-debug"].clear(); + boost::split(mapMultiArgs["-debug"], strMode, boost::is_any_of(",")); + mapArgs["-debug"] = mapMultiArgs["-debug"][mapMultiArgs["-debug"].size() - 1]; + + fDebug = mapArgs["-debug"] != "0"; + + return "Debug mode: " + (fDebug ? strMode : "off"); +} + UniValue mnsync(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index da6e40c94e..ce07e2575c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -258,6 +258,7 @@ static const CRPCCommand vRPCCommands[] = // --------------------- ------------------------ ----------------------- ---------- /* Overall control/query calls */ { "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */ + { "control", "debug", &debug, true }, { "control", "help", &help, true }, { "control", "stop", &stop, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 7dfb5552b6..a1e30d9220 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -232,6 +232,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp); extern UniValue encryptwallet(const UniValue& params, bool fHelp); extern UniValue validateaddress(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp); +extern UniValue debug(const UniValue& params, bool fHelp); extern UniValue getwalletinfo(const UniValue& params, bool fHelp); extern UniValue getblockchaininfo(const UniValue& params, bool fHelp); extern UniValue getnetworkinfo(const UniValue& params, bool fHelp); diff --git a/src/util.cpp b/src/util.cpp index bcc9dbff79..1b82ea160b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -253,16 +253,26 @@ bool LogAcceptCategory(const char* category) { if (category != NULL) { - if (!fDebug) - return false; - // Give each thread quick access to -debug settings. // This helps prevent issues debugging global destructors, // where mapMultiArgs might be deleted before another // global destructor calls LogPrint() static boost::thread_specific_ptr > ptrCategory; + + if (!fDebug) { + if (ptrCategory.get() != NULL) { + LogPrintf("debug turned off: thread %s\n", GetThreadName()); + ptrCategory.release(); + } + return false; + } + if (ptrCategory.get() == NULL) { + std::string strThreadName = GetThreadName(); + LogPrintf("debug turned on:\n"); + for (int i = 0; i < (int)mapMultiArgs["-debug"].size(); ++i) + LogPrintf(" thread %s category %s\n", strThreadName, mapMultiArgs["-debug"][i]); const vector& categories = mapMultiArgs["-debug"]; ptrCategory.reset(new set(categories.begin(), categories.end())); // thread_specific_ptr automatically deletes the set when the thread ends.