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

llvm-svn: 294939
This commit is contained in:
Pavel Labath 2017-02-13 11:03:17 +00:00
parent 796e0d6df1
commit 6302bf6a26
7 changed files with 31 additions and 79 deletions

View File

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

View File

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

View File

@ -84,20 +84,6 @@ void Log::VAPrintf(const char *format, va_list args) {
WriteMessage(message.str());
}
//----------------------------------------------------------------------
// 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
//----------------------------------------------------------------------
@ -308,14 +294,6 @@ void Log::ListAllLogChannels(Stream *strm) {
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;

View File

@ -267,5 +267,5 @@ void StringList::LogDump(Log *log, const char *name) {
if (name)
strm.Printf("End %s.\n", name);
log->Debug("%s", strm.GetData());
LLDB_LOGV(log, "{0}", strm.GetData());
}

View File

@ -660,11 +660,9 @@ FormatManager::GetFormat(ValueObject &valobj,
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 &valobj,
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(ValueObject &valobj,
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(ValueObject &valobj,
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(ValueObject &valobj,
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(ValueObject &valobj,
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 &valobj,
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 &valobj,
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;
}

View File

@ -339,16 +339,16 @@ ClangExpressionParser::ClangExpressionParser(ExecutionContextScope *exe_scope,
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");

View File

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