Add ability to change debug category on the fly from console

NOTE: Before switching to another debug catgory you'd need to turn debugging off via "debug 0"
      and wait a bit (each thread (de)activates debug mode on its own)
This commit is contained in:
UdjinM6 2016-03-15 01:56:55 +03:00 committed by Holger Schinzel
parent a7fd7821e9
commit 2fc05e5b9d
4 changed files with 40 additions and 3 deletions

View File

@ -24,6 +24,7 @@
#include <stdint.h>
#include <boost/assign/list_of.hpp>
#include <boost/algorithm/string.hpp>
#include <univalue.h>
@ -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)

View File

@ -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 },

View File

@ -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);

View File

@ -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<set<string> > 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<string>& categories = mapMultiArgs["-debug"];
ptrCategory.reset(new set<string>(categories.begin(), categories.end()));
// thread_specific_ptr automatically deletes the set when the thread ends.