Skip to content

Commit

Permalink
[Logging] Replace Log::Printf with LLDB_LOG macro (NFC)
Browse files Browse the repository at this point in the history
This patch replaces explicit calls to log::Printf with the new LLDB_LOGF
macro. The macro is similar to LLDB_LOG but supports printf-style format
strings, instead of formatv-style format strings.

So instead of writing:

  if (log)
    log->Printf("%s\n", str);

You'd write:

  LLDB_LOG(log, "%s\n", str);

This change was done mechanically with the command below. I replaced the
spurious if-checks with vim, since I know how to do multi-line
replacements with it.

  find . -type f -name '*.cpp' -exec \
  sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" +

Differential revision: https://reviews.llvm.org/D65128

llvm-svn: 366936
  • Loading branch information
JDevlieghere committed Jul 24, 2019
1 parent 2bf871b commit 63e5fb7
Show file tree
Hide file tree
Showing 190 changed files with 5,364 additions and 5,934 deletions.
8 changes: 8 additions & 0 deletions lldb/include/lldb/Utility/Log.h
Expand Up @@ -142,6 +142,7 @@ class Log final {
std::forward<Args>(args)...));
}

/// Prefer using LLDB_LOGF whenever possible.
void Printf(const char *format, ...) __attribute__((format(printf, 2, 3)));

void Error(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
Expand Down Expand Up @@ -212,6 +213,13 @@ class Log final {
log_private->Format(__FILE__, __func__, __VA_ARGS__); \
} while (0)

#define LLDB_LOGF(log, ...) \
do { \
::lldb_private::Log *log_private = (log); \
if (log_private) \
log_private->Printf(__VA_ARGS__); \
} while (0)

#define LLDB_LOGV(log, ...) \
do { \
::lldb_private::Log *log_private = (log); \
Expand Down
100 changes: 47 additions & 53 deletions lldb/source/API/SBDebugger.cpp
Expand Up @@ -680,13 +680,13 @@ lldb::SBTarget SBDebugger::CreateTarget(const char *filename,
}

Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (log)
log->Printf("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
"platform_name=%s, add_dependent_modules=%u, error=%s) => "
"SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
platform_name, add_dependent_modules, sb_error.GetCString(),
static_cast<void *>(target_sp.get()));
LLDB_LOGF(log,
"SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
"platform_name=%s, add_dependent_modules=%u, error=%s) => "
"SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
platform_name, add_dependent_modules, sb_error.GetCString(),
static_cast<void *>(target_sp.get()));

return LLDB_RECORD_RESULT(sb_target);
}
Expand All @@ -710,11 +710,11 @@ SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename,
}

Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (log)
log->Printf("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
"(filename=\"%s\", triple=%s) => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
static_cast<void *>(target_sp.get()));
LLDB_LOGF(log,
"SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
"(filename=\"%s\", triple=%s) => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
static_cast<void *>(target_sp.get()));

return LLDB_RECORD_RESULT(sb_target);
}
Expand Down Expand Up @@ -743,11 +743,11 @@ SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename,
}
}

if (log)
log->Printf("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
"arch=%s) => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename, arch_cstr,
static_cast<void *>(target_sp.get()));
LLDB_LOGF(log,
"SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
"arch=%s) => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename, arch_cstr,
static_cast<void *>(target_sp.get()));

return LLDB_RECORD_RESULT(sb_target);
}
Expand All @@ -772,11 +772,10 @@ SBTarget SBDebugger::CreateTarget(const char *filename) {
}
}
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (log)
log->Printf(
"SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename,
static_cast<void *>(target_sp.get()));
LLDB_LOGF(log,
"SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()), filename,
static_cast<void *>(target_sp.get()));
return LLDB_RECORD_RESULT(sb_target);
}

Expand All @@ -788,11 +787,9 @@ SBTarget SBDebugger::GetDummyTarget() {
sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this());
}
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (log)
log->Printf(
"SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(sb_target.GetSP().get()));
LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(sb_target.GetSP().get()));
return LLDB_RECORD_RESULT(sb_target);
}

Expand All @@ -814,10 +811,9 @@ bool SBDebugger::DeleteTarget(lldb::SBTarget &target) {
}

Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (log)
log->Printf("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(target.m_opaque_sp.get()), result);
LLDB_LOGF(log, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(target.m_opaque_sp.get()), result);

return result;
}
Expand Down Expand Up @@ -914,9 +910,9 @@ SBTarget SBDebugger::GetSelectedTarget() {
if (log) {
SBStream sstr;
sb_target.GetDescription(sstr, eDescriptionLevelBrief);
log->Printf("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(target_sp.get()), sstr.GetData());
LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(target_sp.get()), sstr.GetData());
}

return LLDB_RECORD_RESULT(sb_target);
Expand All @@ -935,9 +931,9 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
if (log) {
SBStream sstr;
sb_target.GetDescription(sstr, eDescriptionLevelBrief);
log->Printf("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(target_sp.get()), sstr.GetData());
LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(target_sp.get()), sstr.GetData());
}
}

Expand All @@ -951,11 +947,10 @@ SBPlatform SBDebugger::GetSelectedPlatform() {
if (debugger_sp) {
sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
}
if (log)
log->Printf("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(sb_platform.GetSP().get()),
sb_platform.GetName());
LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(sb_platform.GetSP().get()),
sb_platform.GetName());
return LLDB_RECORD_RESULT(sb_platform);
}

Expand All @@ -970,11 +965,10 @@ void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) {
debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
}

if (log)
log->Printf("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(sb_platform.GetSP().get()),
sb_platform.GetName());
LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
static_cast<void *>(m_opaque_sp.get()),
static_cast<void *>(sb_platform.GetSP().get()),
sb_platform.GetName());
}

uint32_t SBDebugger::GetNumPlatforms() {
Expand Down Expand Up @@ -1062,7 +1056,7 @@ void SBDebugger::DispatchInput(const void *data, size_t data_len) {
// Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
//
// if (log)
// log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\",
// LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",
// size_t=%" PRIu64 ")",
// m_opaque_sp.get(),
// (int) data_len,
Expand Down Expand Up @@ -1246,10 +1240,9 @@ const char *SBDebugger::GetPrompt() const {

Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));

if (log)
log->Printf("SBDebugger(%p)::GetPrompt () => \"%s\"",
static_cast<void *>(m_opaque_sp.get()),
(m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));
LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"",
static_cast<void *>(m_opaque_sp.get()),
(m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));

return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()
: nullptr);
Expand Down Expand Up @@ -1374,7 +1367,8 @@ bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {

if (platform_sp) {
if (log && sysroot)
log->Printf("SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")", sysroot);
LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")",
sysroot);
platform_sp->SetSDKRootDirectory(ConstString(sysroot));
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/API/SBFrame.cpp
Expand Up @@ -1120,10 +1120,10 @@ lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
}
}

if (expr_log)
expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is "
"%s, summary %s **",
expr_result.GetValue(), expr_result.GetSummary());
LLDB_LOGF(expr_log,
"** [SBFrame::EvaluateExpression] Expression result is "
"%s, summary %s **",
expr_result.GetValue(), expr_result.GetSummary());

return LLDB_RECORD_RESULT(expr_result);
}
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/API/SBTarget.cpp
Expand Up @@ -2355,10 +2355,10 @@ lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
}
}
if (expr_log)
expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
"%s, summary %s **",
expr_result.GetValue(), expr_result.GetSummary());
LLDB_LOGF(expr_log,
"** [SBTarget::EvaluateExpression] Expression result is "
"%s, summary %s **",
expr_result.GetValue(), expr_result.GetSummary());
return LLDB_RECORD_RESULT(expr_result);
}

Expand Down
21 changes: 10 additions & 11 deletions lldb/source/Breakpoint/Breakpoint.cpp
Expand Up @@ -496,10 +496,10 @@ void Breakpoint::ClearAllBreakpointSites() {
void Breakpoint::ModulesChanged(ModuleList &module_list, bool load,
bool delete_locations) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf("Breakpoint::ModulesChanged: num_modules: %zu load: %i "
"delete_locations: %i\n",
module_list.GetSize(), load, delete_locations);
LLDB_LOGF(log,
"Breakpoint::ModulesChanged: num_modules: %zu load: %i "
"delete_locations: %i\n",
module_list.GetSize(), load, delete_locations);

std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
if (load) {
Expand Down Expand Up @@ -550,10 +550,10 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load,
seen = true;

if (!break_loc_sp->ResolveBreakpointSite()) {
if (log)
log->Printf("Warning: could not set breakpoint site for "
"breakpoint location %d of breakpoint %d.\n",
break_loc_sp->GetID(), GetID());
LLDB_LOGF(log,
"Warning: could not set breakpoint site for "
"breakpoint location %d of breakpoint %d.\n",
break_loc_sp->GetID(), GetID());
}
}
}
Expand Down Expand Up @@ -659,9 +659,8 @@ static bool SymbolContextsMightBeEquivalent(SymbolContext &old_sc,
void Breakpoint::ModuleReplaced(ModuleSP old_module_sp,
ModuleSP new_module_sp) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf("Breakpoint::ModulesReplaced for %s\n",
old_module_sp->GetSpecificationDescription().c_str());
LLDB_LOGF(log, "Breakpoint::ModulesReplaced for %s\n",
old_module_sp->GetSpecificationDescription().c_str());
// First find all the locations that are in the old module

BreakpointLocationCollection old_break_locs;
Expand Down
13 changes: 6 additions & 7 deletions lldb/source/Breakpoint/BreakpointLocation.cpp
Expand Up @@ -257,9 +257,8 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
condition_text, llvm::StringRef(), language, Expression::eResultTypeAny,
EvaluateExpressionOptions(), nullptr, error));
if (error.Fail()) {
if (log)
log->Printf("Error getting condition expression: %s.",
error.AsCString());
LLDB_LOGF(log, "Error getting condition expression: %s.",
error.AsCString());
m_user_expression_sp.reset();
return true;
}
Expand Down Expand Up @@ -312,8 +311,8 @@ bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
ret = result_value_sp->IsLogicalTrue(error);
if (log) {
if (error.Success()) {
log->Printf("Condition successfully evaluated, result is %s.\n",
ret ? "true" : "false");
LLDB_LOGF(log, "Condition successfully evaluated, result is %s.\n",
ret ? "true" : "false");
} else {
error.SetErrorString(
"Failed to get an integer result from the expression");
Expand Down Expand Up @@ -408,8 +407,8 @@ bool BreakpointLocation::ShouldStop(StoppointCallbackContext *context) {
if (log) {
StreamString s;
GetDescription(&s, lldb::eDescriptionLevelVerbose);
log->Printf("Hit breakpoint location: %s, %s.\n", s.GetData(),
should_stop ? "stopping" : "continuing");
LLDB_LOGF(log, "Hit breakpoint location: %s, %s.\n", s.GetData(),
should_stop ? "stopping" : "continuing");
}

return should_stop;
Expand Down
20 changes: 10 additions & 10 deletions lldb/source/Breakpoint/BreakpointResolver.cpp
Expand Up @@ -294,18 +294,18 @@ void BreakpointResolver::AddLocation(SearchFilter &filter,
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
Address line_start = sc.line_entry.range.GetBaseAddress();
if (!line_start.IsValid()) {
if (log)
log->Printf("error: Unable to set breakpoint %s at file address "
"0x%" PRIx64 "\n",
log_ident.str().c_str(), line_start.GetFileAddress());
LLDB_LOGF(log,
"error: Unable to set breakpoint %s at file address "
"0x%" PRIx64 "\n",
log_ident.str().c_str(), line_start.GetFileAddress());
return;
}

if (!filter.AddressPasses(line_start)) {
if (log)
log->Printf("Breakpoint %s at file address 0x%" PRIx64
" didn't pass the filter.\n",
log_ident.str().c_str(), line_start.GetFileAddress());
LLDB_LOGF(log,
"Breakpoint %s at file address 0x%" PRIx64
" didn't pass the filter.\n",
log_ident.str().c_str(), line_start.GetFileAddress());
}

// If the line number is before the prologue end, move it there...
Expand All @@ -329,8 +329,8 @@ void BreakpointResolver::AddLocation(SearchFilter &filter,
if (log && bp_loc_sp && !m_breakpoint->IsInternal()) {
StreamString s;
bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
log->Printf("Added location (skipped prologue: %s): %s \n",
skipped_prologue ? "yes" : "no", s.GetData());
LLDB_LOGF(log, "Added location (skipped prologue: %s): %s \n",
skipped_prologue ? "yes" : "no", s.GetData());
}
}

Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Breakpoint/BreakpointResolverAddress.cpp
Expand Up @@ -149,8 +149,7 @@ BreakpointResolverAddress::SearchCallback(SearchFilter &filter,
bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
Log *log(
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf("Added location: %s\n", s.GetData());
LLDB_LOGF(log, "Added location: %s\n", s.GetData());
}
} else {
BreakpointLocationSP loc_sp = m_breakpoint->GetLocationAtIndex(0);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointResolverName.cpp
Expand Up @@ -388,7 +388,7 @@ BreakpointResolverName::SearchCallback(SearchFilter &filter,
if (log) {
StreamString s;
bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
log->Printf("Added location: %s\n", s.GetData());
LLDB_LOGF(log, "Added location: %s\n", s.GetData());
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Commands/CommandObjectTarget.cpp
Expand Up @@ -1064,9 +1064,10 @@ class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed {
if (from[0] && to[0]) {
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
if (log) {
log->Printf("target modules search path adding ImageSearchPath "
"pair: '%s' -> '%s'",
from, to);
LLDB_LOGF(log,
"target modules search path adding ImageSearchPath "
"pair: '%s' -> '%s'",
from, to);
}
bool last_pair = ((argc - i) == 2);
target->GetImageSearchPathList().Append(
Expand Down

0 comments on commit 63e5fb7

Please sign in to comment.