From 3b570559f8d39a5d4cffd01b8091c3133f7750dc Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Tue, 8 Oct 2013 12:09:40 +0200 Subject: re-work -debug switch handling - re-work -debug help message text - make -debug log every debugging information again (even all categories) - remove unneeded fDebug checks in front of LogPrint()/qDebug(), as that check is done in LogPrintf() when category is != NULL (true for all LogPrint() calls - remove fDebug ONLY in code which is NOT performance-critical - harmonize addrman category name - deprecate -debugnet usage, should be used via -debug=net and remove the corresponding global --- src/addrman.h | 4 ++-- src/init.cpp | 31 ++++++++++++++++++++++--------- src/main.cpp | 6 +++--- src/qt/paymentrequestplus.cpp | 3 +-- src/qt/paymentserver.cpp | 16 +++++----------- src/util.cpp | 17 +++++++++++++---- src/util.h | 1 - 7 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/addrman.h b/src/addrman.h index 081543ace4..d703e1091e 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -419,7 +419,7 @@ public: Check(); } if (fRet) - LogPrint("addr", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew); + LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort().c_str(), source.ToString().c_str(), nTried, nNew); return fRet; } @@ -435,7 +435,7 @@ public: Check(); } if (nAdd) - LogPrint("addr", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew); + LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString().c_str(), nTried, nNew); return nAdd > 0; } diff --git a/src/init.cpp b/src/init.cpp index 72b53ebecc..647b8d52ea 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -215,8 +215,18 @@ std::string HelpMessage(HelpMessageMode hmm) #endif #endif strUsage += " -paytxfee= " + _("Fee per KB to add to transactions you send") + "\n"; - strUsage += " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n"; - strUsage += " -debugnet " + _("Output extra network debugging information") + "\n"; + strUsage += " -debug= " + _("Output debugging information (default: 0, supplying is optional)") + "\n"; + strUsage += _("If is not supplied, output all debugging information.") + "\n"; + strUsage += _(" can be:"); + strUsage += " addrman, alert, coindb, db, lock, rand, rpc, selectcoins, mempool, net"; // Don't translate these and qt below + if (hmm == HMM_BITCOIN_QT) + { + strUsage += ", qt.\n"; + } + else + { + strUsage += ".\n"; + } strUsage += " -logtimestamps " + _("Prepend debug output with timestamp") + "\n"; strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n"; strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n"; @@ -457,7 +467,16 @@ bool AppInit2(boost::thread_group& threadGroup) // ********************************************************* Step 3: parameter-to-internal-flags - if (mapMultiArgs.count("-debug")) fDebug = true; + fDebug = !mapMultiArgs["-debug"].empty(); + // Special-case: if -debug=0/-nodebug is set, turn off debugging messages + const vector& categories = mapMultiArgs["-debug"]; + if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), string("0")) != categories.end()) + fDebug = false; + + // Check for -debugnet (deprecated) + if (GetBoolArg("-debugnet", false)) + InitWarning(_("Warning: Deprecated argument -debugnet ignored, use -debug=net")); + fBenchmark = GetBoolArg("-benchmark", false); mempool.fChecks = GetBoolArg("-checkmempool", RegTest()); Checkpoints::fEnabled = GetBoolArg("-checkpoints", true); @@ -471,12 +490,6 @@ bool AppInit2(boost::thread_group& threadGroup) else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; - // -debug implies fDebug* - if (fDebug) - fDebugNet = true; - else - fDebugNet = GetBoolArg("-debugnet", false); - if (fDaemon) fServer = true; else diff --git a/src/main.cpp b/src/main.cpp index 3d339b4fdd..640fbac8bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3544,10 +3544,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return error("message getdata size() = %"PRIszu"", vInv.size()); } - if (fDebugNet || (vInv.size() != 1)) + if (fDebug || (vInv.size() != 1)) LogPrint("net", "received getdata (%"PRIszu" invsz)\n", vInv.size()); - if ((fDebugNet && vInv.size() > 0) || (vInv.size() == 1)) + if ((fDebug && vInv.size() > 0) || (vInv.size() == 1)) LogPrint("net", "received getdata for: %s\n", vInv[0].ToString().c_str()); pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end()); @@ -4213,7 +4213,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) const CInv& inv = (*pto->mapAskFor.begin()).second; if (!AlreadyHave(inv)) { - if (fDebugNet) + if (fDebug) LogPrint("net", "sending getdata: %s\n", inv.ToString().c_str()); vGetData.push_back(inv); if (vGetData.size() >= 1000) diff --git a/src/qt/paymentrequestplus.cpp b/src/qt/paymentrequestplus.cpp index f6a898ff7c..c8afd837d2 100644 --- a/src/qt/paymentrequestplus.cpp +++ b/src/qt/paymentrequestplus.cpp @@ -75,8 +75,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c digestAlgorithm = EVP_sha1(); } else if (paymentRequest.pki_type() == "none") { - if (fDebug) - qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none"; + qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none"; return false; } else { diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 43c4bdd191..0f386680ac 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -87,9 +87,7 @@ static QList savedPaymentRequests; static void ReportInvalidCertificate(const QSslCertificate& cert) { - if (fDebug) { - qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName); - } + qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName); } // @@ -160,8 +158,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store) continue; } } - if (fDebug) - qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates"; + qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates"; // Project for another day: // Fetch certificate revocation lists, and add them to certStore. @@ -375,8 +372,7 @@ void PaymentServer::handleURIOrFile(const QString& s) QString decoded = QUrl::fromPercentEncoding(temp); QUrl fetchUrl(decoded, QUrl::StrictMode); - if (fDebug) - qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")"; + qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")"; if (fetchUrl.isValid()) fetchRequest(fetchUrl); @@ -475,8 +471,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList mapArgs; map > mapMultiArgs; bool fDebug = false; -bool fDebugNet = false; bool fPrintToConsole = false; bool fPrintToDebugger = false; bool fDaemon = false; @@ -226,10 +225,20 @@ int LogPrint(const char* category, const char* pszFormat, ...) { if (category != NULL) { - if (!fDebug) return 0; - const vector& categories = mapMultiArgs["-debug"]; - if (find(categories.begin(), categories.end(), string(category)) == categories.end()) + if (!fDebug) return 0; + + const vector& categories = mapMultiArgs["-debug"]; + bool allCategories = count(categories.begin(), categories.end(), string("")); + + // Only look for categories, if not -debug/-debug=1 was passed, + // as that implies every category should be logged. + if (!allCategories) + { + // Category was not found (not supplied via -debug=) + if (find(categories.begin(), categories.end(), string(category)) == categories.end()) + return 0; + } } int ret = 0; // Returns total number of characters written diff --git a/src/util.h b/src/util.h index 258910e2fb..2573694046 100644 --- a/src/util.h +++ b/src/util.h @@ -140,7 +140,6 @@ inline void MilliSleep(int64 n) extern std::map mapArgs; extern std::map > mapMultiArgs; extern bool fDebug; -extern bool fDebugNet; extern bool fPrintToConsole; extern bool fPrintToDebugger; extern bool fDaemon; -- cgit v1.2.3