[Lldb-commits] [lldb] r294939 - Clean up debug logging

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 13 03:03:18 PST 2017


Author: labath
Date: Mon Feb 13 05:03:17 2017
New Revision: 294939

URL: http://llvm.org/viewvc/llvm-project?rev=294939&view=rev
Log:
Clean up debug logging

Summary:
We've had two ways to print a "debug" log message.
- Log::GetDebug() was testing a Stream flag which was never set.
- Log::Debug() was checking for the presence of "log enable --debug"
flag.

Given that these two were used very rarely and we already have a
different way to specify "I want a more verbose log", I propose to remove
these two functions and migrate the callers to LLDB_LOGV. This commit
does that.

Reviewers: clayborg, zturner

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D29823

Modified:
    lldb/trunk/include/lldb/Core/Log.h
    lldb/trunk/source/Commands/CommandObjectLog.cpp
    lldb/trunk/source/Core/Log.cpp
    lldb/trunk/source/Core/StringList.cpp
    lldb/trunk/source/DataFormatters/FormatManager.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp

Modified: lldb/trunk/include/lldb/Core/Log.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Log.h?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Log.h (original)
+++ lldb/trunk/include/lldb/Core/Log.h Mon Feb 13 05:03:17 2017
@@ -29,7 +29,6 @@
 //----------------------------------------------------------------------
 #define LLDB_LOG_OPTION_THREADSAFE (1u << 0)
 #define LLDB_LOG_OPTION_VERBOSE (1u << 1)
-#define LLDB_LOG_OPTION_DEBUG (1u << 2)
 #define LLDB_LOG_OPTION_PREPEND_SEQUENCE (1u << 3)
 #define LLDB_LOG_OPTION_PREPEND_TIMESTAMP (1u << 4)
 #define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD (1u << 5)
@@ -122,8 +121,6 @@ public:
   void LogIf(uint32_t mask, const char *fmt, ...)
       __attribute__((format(printf, 3, 4)));
 
-  void Debug(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
-
   void Error(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
 
   void VAError(const char *format, va_list args);
@@ -142,8 +139,6 @@ public:
 
   bool GetVerbose() const;
 
-  bool GetDebug() const;
-
   void SetStream(const std::shared_ptr<llvm::raw_ostream> &stream_sp) {
     m_stream_sp = stream_sp;
   }

Modified: lldb/trunk/source/Commands/CommandObjectLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectLog.cpp?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectLog.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectLog.cpp Mon Feb 13 05:03:17 2017
@@ -41,7 +41,6 @@ static OptionDefinition g_log_options[]
   { LLDB_OPT_SET_1, false, "file",       'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, "Set the destination file to log to." },
   { LLDB_OPT_SET_1, false, "threadsafe", 't', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,     "Enable thread safe logging to avoid interweaved log lines." },
   { LLDB_OPT_SET_1, false, "verbose",    'v', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,     "Enable verbose logging." },
-  { LLDB_OPT_SET_1, false, "debug",      'g', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,     "Enable debug logging." },
   { LLDB_OPT_SET_1, false, "sequence",   's', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,     "Prepend all log lines with an increasing integer sequence id." },
   { LLDB_OPT_SET_1, false, "timestamp",  'T', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,     "Prepend all log lines with a timestamp." },
   { LLDB_OPT_SET_1, false, "pid-tid",    'p', OptionParser::eNoArgument,       nullptr, nullptr, 0, eArgTypeNone,     "Prepend all log lines with the process and thread ID that generates the log line." },
@@ -110,9 +109,6 @@ public:
       case 'v':
         log_options |= LLDB_LOG_OPTION_VERBOSE;
         break;
-      case 'g':
-        log_options |= LLDB_LOG_OPTION_DEBUG;
-        break;
       case 's':
         log_options |= LLDB_LOG_OPTION_PREPEND_SEQUENCE;
         break;

Modified: lldb/trunk/source/Core/Log.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Log.cpp?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/source/Core/Log.cpp (original)
+++ lldb/trunk/source/Core/Log.cpp Mon Feb 13 05:03:17 2017
@@ -85,20 +85,6 @@ void Log::VAPrintf(const char *format, v
 }
 
 //----------------------------------------------------------------------
-// Print debug strings if and only if the global debug option is set to
-// a non-zero value.
-//----------------------------------------------------------------------
-void Log::Debug(const char *format, ...) {
-  if (!GetOptions().Test(LLDB_LOG_OPTION_DEBUG))
-    return;
-
-  va_list args;
-  va_start(args, format);
-  VAPrintf(format, args);
-  va_end(args);
-}
-
-//----------------------------------------------------------------------
 // Log only if all of the bits are set
 //----------------------------------------------------------------------
 void Log::LogIf(uint32_t bits, const char *format, ...) {
@@ -308,14 +294,6 @@ void Log::ListAllLogChannels(Stream *str
 
 bool Log::GetVerbose() const { return m_options.Test(LLDB_LOG_OPTION_VERBOSE); }
 
-//------------------------------------------------------------------
-// Returns true if the debug flag bit is set in this stream.
-//------------------------------------------------------------------
-bool Log::GetDebug() const {
-  // TODO: remove and clean up callers
-  return false;
-}
-
 void Log::WriteHeader(llvm::raw_ostream &OS, llvm::StringRef file,
                       llvm::StringRef function) {
   static uint32_t g_sequence_id = 0;

Modified: lldb/trunk/source/Core/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StringList.cpp?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/source/Core/StringList.cpp (original)
+++ lldb/trunk/source/Core/StringList.cpp Mon Feb 13 05:03:17 2017
@@ -267,5 +267,5 @@ void StringList::LogDump(Log *log, const
   if (name)
     strm.Printf("End %s.\n", name);
 
-  log->Debug("%s", strm.GetData());
+  LLDB_LOGV(log, "{0}", strm.GetData());
 }

Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Mon Feb 13 05:03:17 2017
@@ -660,11 +660,9 @@ FormatManager::GetFormat(ValueObject &va
       if (log) {
         log->Printf(
             "[FormatManager::GetFormat] Cache search success. Returning.");
-        if (log->GetDebug())
-          log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64
-                      " - Cache Misses: %" PRIu64,
-                      m_format_cache.GetCacheHits(),
-                      m_format_cache.GetCacheMisses());
+        LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+                  m_format_cache.GetCacheHits(),
+                  m_format_cache.GetCacheMisses());
       }
       return retval;
     }
@@ -705,10 +703,8 @@ FormatManager::GetFormat(ValueObject &va
                   match_data.GetTypeForCache().AsCString("<invalid>"));
     m_format_cache.SetFormat(match_data.GetTypeForCache(), retval);
   }
-  if (log && log->GetDebug())
-    log->Printf("[FormatManager::GetFormat] Cache hits: %" PRIu64
-                " - Cache Misses: %" PRIu64,
-                m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
+  LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+            m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
   return retval;
 }
 
@@ -742,11 +738,9 @@ FormatManager::GetSummaryFormat(ValueObj
       if (log) {
         log->Printf("[FormatManager::GetSummaryFormat] Cache search success. "
                     "Returning.");
-        if (log->GetDebug())
-          log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64
-                      " - Cache Misses: %" PRIu64,
-                      m_format_cache.GetCacheHits(),
-                      m_format_cache.GetCacheMisses());
+        LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+                  m_format_cache.GetCacheHits(),
+                  m_format_cache.GetCacheMisses());
       }
       return retval;
     }
@@ -787,10 +781,8 @@ FormatManager::GetSummaryFormat(ValueObj
                   match_data.GetTypeForCache().AsCString("<invalid>"));
     m_format_cache.SetSummary(match_data.GetTypeForCache(), retval);
   }
-  if (log && log->GetDebug())
-    log->Printf("[FormatManager::GetSummaryFormat] Cache hits: %" PRIu64
-                " - Cache Misses: %" PRIu64,
-                m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
+  LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+            m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
   return retval;
 }
 
@@ -825,11 +817,9 @@ FormatManager::GetSyntheticChildren(Valu
       if (log) {
         log->Printf("[FormatManager::GetSyntheticChildren] Cache search "
                     "success. Returning.");
-        if (log->GetDebug())
-          log->Printf(
-              "[FormatManager::GetSyntheticChildren] Cache hits: %" PRIu64
-              " - Cache Misses: %" PRIu64,
-              m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
+        LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+                  m_format_cache.GetCacheHits(),
+                  m_format_cache.GetCacheMisses());
       }
       return retval;
     }
@@ -871,10 +861,8 @@ FormatManager::GetSyntheticChildren(Valu
           match_data.GetTypeForCache().AsCString("<invalid>"));
     m_format_cache.SetSynthetic(match_data.GetTypeForCache(), retval);
   }
-  if (log && log->GetDebug())
-    log->Printf("[FormatManager::GetSyntheticChildren] Cache hits: %" PRIu64
-                " - Cache Misses: %" PRIu64,
-                m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
+  LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+            m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
   return retval;
 }
 #endif
@@ -895,11 +883,9 @@ FormatManager::GetValidator(ValueObject
       if (log) {
         log->Printf(
             "[FormatManager::GetValidator] Cache search success. Returning.");
-        if (log->GetDebug())
-          log->Printf("[FormatManager::GetValidator] Cache hits: %" PRIu64
-                      " - Cache Misses: %" PRIu64,
-                      m_format_cache.GetCacheHits(),
-                      m_format_cache.GetCacheMisses());
+        LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+                  m_format_cache.GetCacheHits(),
+                  m_format_cache.GetCacheMisses());
       }
       return retval;
     }
@@ -940,10 +926,8 @@ FormatManager::GetValidator(ValueObject
                   match_data.GetTypeForCache().AsCString("<invalid>"));
     m_format_cache.SetValidator(match_data.GetTypeForCache(), retval);
   }
-  if (log && log->GetDebug())
-    log->Printf("[FormatManager::GetValidator] Cache hits: %" PRIu64
-                " - Cache Misses: %" PRIu64,
-                m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
+  LLDB_LOGV(log, "Cache hits: {0} - Cache Misses: {1}",
+            m_format_cache.GetCacheHits(), m_format_cache.GetCacheMisses());
   return retval;
 }
 

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Mon Feb 13 05:03:17 2017
@@ -339,16 +339,16 @@ ClangExpressionParser::ClangExpressionPa
         lang_rt->GetOverrideExprOptions(m_compiler->getTargetOpts());
 
   if (overridden_target_opts)
-    if (log) {
-      log->Debug(
-          "Using overridden target options for the expression evaluation");
+    if (log && log->GetVerbose()) {
+      LLDB_LOGV(
+          log, "Using overridden target options for the expression evaluation");
 
       auto opts = m_compiler->getTargetOpts();
-      log->Debug("Triple: '%s'", opts.Triple.c_str());
-      log->Debug("CPU: '%s'", opts.CPU.c_str());
-      log->Debug("FPMath: '%s'", opts.FPMath.c_str());
-      log->Debug("ABI: '%s'", opts.ABI.c_str());
-      log->Debug("LinkerVersion: '%s'", opts.LinkerVersion.c_str());
+      LLDB_LOGV(log, "Triple: '{0}'", opts.Triple);
+      LLDB_LOGV(log, "CPU: '{0}'", opts.CPU);
+      LLDB_LOGV(log, "FPMath: '{0}'", opts.FPMath);
+      LLDB_LOGV(log, "ABI: '{0}'", opts.ABI);
+      LLDB_LOGV(log, "LinkerVersion: '{0}'", opts.LinkerVersion);
       StringList::LogDump(log, opts.FeaturesAsWritten, "FeaturesAsWritten");
       StringList::LogDump(log, opts.Features, "Features");
       StringList::LogDump(log, opts.Reciprocals, "Reciprocals");

Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp?rev=294939&r1=294938&r2=294939&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp Mon Feb 13 05:03:17 2017
@@ -3128,9 +3128,8 @@ bool RSModuleDescriptor::ParseRSInfo() {
     // in numeric fields at the moment
     uint64_t n_lines;
     if (val.getAsInteger(10, n_lines)) {
-      if (log)
-        log->Debug("Failed to parse non-numeric '.rs.info' section %s",
-                   line->str().c_str());
+      LLDB_LOGV(log, "Failed to parse non-numeric '.rs.info' section {0}",
+                line->str());
       continue;
     }
     if (info_lines.end() - (line + 1) < (ptrdiff_t)n_lines)




More information about the lldb-commits mailing list