Skip to content

Commit bc2a07c

Browse files
committed
[lldb] Improve logging for process state change (NFC)
This patch improves process state change logging messages to include to process plugin name. It also replaces the `LLDB_LOGF` macro by `LLDB_LOG` macro that adds the class and method name in the log message using the compiler instead of having to change the string litteral for every method. This is very useful when investigating interactions between different types of process plugins. That comes very handy when investigating bugs related to interactive scripted process debugging. Differential Revision: https://reviews.llvm.org/D148399 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent e0cc8db commit bc2a07c

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

lldb/source/Target/Process.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,14 +1162,16 @@ bool Process::SetExitStatus(int status, const char *cstr) {
11621162
std::lock_guard<std::mutex> guard(m_exit_status_mutex);
11631163

11641164
Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
1165-
LLDB_LOGF(
1166-
log, "Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)",
1167-
status, status, cstr ? "\"" : "", cstr ? cstr : "NULL", cstr ? "\"" : "");
1165+
LLDB_LOG(log, "(plugin = %s status=%i (0x%8.8x), description=%s%s%s)",
1166+
GetPluginName().data(), status, status, cstr ? "\"" : "",
1167+
cstr ? cstr : "NULL", cstr ? "\"" : "");
11681168

11691169
// We were already in the exited state
11701170
if (m_private_state.GetValue() == eStateExited) {
1171-
LLDB_LOGF(log, "Process::SetExitStatus () ignoring exit status because "
1172-
"state was already set to eStateExited");
1171+
LLDB_LOG(log,
1172+
"(plugin = %s) ignoring exit status because state was already set "
1173+
"to eStateExited",
1174+
GetPluginName().data());
11731175
return false;
11741176
}
11751177

@@ -1453,8 +1455,8 @@ void Process::SetPublicState(StateType new_state, bool restarted) {
14531455
}
14541456

14551457
Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
1456-
LLDB_LOGF(log, "Process::SetPublicState (state = %s, restarted = %i)",
1457-
StateAsCString(new_state), restarted);
1458+
LLDB_LOG(log, "(plugin = %s, state = %s, restarted = %i)",
1459+
GetPluginName().data(), StateAsCString(new_state), restarted);
14581460
const StateType old_state = m_public_state.GetValue();
14591461
m_public_state.SetValue(new_state);
14601462

@@ -1463,16 +1465,16 @@ void Process::SetPublicState(StateType new_state, bool restarted) {
14631465
// program to run.
14641466
if (!StateChangedIsExternallyHijacked()) {
14651467
if (new_state == eStateDetached) {
1466-
LLDB_LOGF(log,
1467-
"Process::SetPublicState (%s) -- unlocking run lock for detach",
1468-
StateAsCString(new_state));
1468+
LLDB_LOG(log,
1469+
"(plugin = %s, state = %s) -- unlocking run lock for detach",
1470+
GetPluginName().data(), StateAsCString(new_state));
14691471
m_public_run_lock.SetStopped();
14701472
} else {
14711473
const bool old_state_is_stopped = StateIsStoppedState(old_state, false);
14721474
if ((old_state_is_stopped != new_state_is_stopped)) {
14731475
if (new_state_is_stopped && !restarted) {
1474-
LLDB_LOGF(log, "Process::SetPublicState (%s) -- unlocking run lock",
1475-
StateAsCString(new_state));
1476+
LLDB_LOG(log, "(plugin = %s, state = %s) -- unlocking run lock",
1477+
GetPluginName().data(), StateAsCString(new_state));
14761478
m_public_run_lock.SetStopped();
14771479
}
14781480
}
@@ -1482,10 +1484,11 @@ void Process::SetPublicState(StateType new_state, bool restarted) {
14821484

14831485
Status Process::Resume() {
14841486
Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
1485-
LLDB_LOGF(log, "Process::Resume -- locking run lock");
1487+
LLDB_LOG(log, "(plugin = %s) -- locking run lock", GetPluginName().data());
14861488
if (!m_public_run_lock.TrySetRunning()) {
14871489
Status error("Resume request failed - process still running.");
1488-
LLDB_LOGF(log, "Process::Resume: -- TrySetRunning failed, not resuming.");
1490+
LLDB_LOG(log, "(plugin = %s) -- TrySetRunning failed, not resuming.",
1491+
GetPluginName().data());
14891492
return error;
14901493
}
14911494
Status error = PrivateResume();
@@ -1558,7 +1561,8 @@ void Process::SetPrivateState(StateType new_state) {
15581561
Log *log(GetLog(LLDBLog::State | LLDBLog::Process | LLDBLog::Unwind));
15591562
bool state_changed = false;
15601563

1561-
LLDB_LOGF(log, "Process::SetPrivateState (%s)", StateAsCString(new_state));
1564+
LLDB_LOG(log, "(plugin = %s, state = %s)", GetPluginName().data(),
1565+
StateAsCString(new_state));
15621566

15631567
std::lock_guard<std::recursive_mutex> thread_guard(m_thread_list.GetMutex());
15641568
std::lock_guard<std::recursive_mutex> guard(m_private_state.GetMutex());
@@ -1599,15 +1603,15 @@ void Process::SetPrivateState(StateType new_state) {
15991603
if (!m_mod_id.IsLastResumeForUserExpression())
16001604
m_mod_id.SetStopEventForLastNaturalStopID(event_sp);
16011605
m_memory_cache.Clear();
1602-
LLDB_LOGF(log, "Process::SetPrivateState (%s) stop_id = %u",
1603-
StateAsCString(new_state), m_mod_id.GetStopID());
1606+
LLDB_LOG(log, "(plugin = %s, state = %s, stop_id = %u",
1607+
GetPluginName().data(), StateAsCString(new_state),
1608+
m_mod_id.GetStopID());
16041609
}
16051610

16061611
m_private_state_broadcaster.BroadcastEvent(event_sp);
16071612
} else {
1608-
LLDB_LOGF(log,
1609-
"Process::SetPrivateState (%s) state didn't change. Ignoring...",
1610-
StateAsCString(new_state));
1613+
LLDB_LOG(log, "(plugin = %s, state = %s) state didn't change. Ignoring...",
1614+
GetPluginName().data(), StateAsCString(new_state));
16111615
}
16121616
}
16131617

0 commit comments

Comments
 (0)