This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Improve logging for process state change (NFC)
ClosedPublic

Authored by mib on Apr 14 2023, 5:03 PM.

Details

Summary

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.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Apr 14 2023, 5:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 5:03 PM
mib requested review of this revision.Apr 14 2023, 5:03 PM

I think a lot of this can be simplified by using LLDB_LOG instead of LLDB_LOGF.

+1 to what Jonas said. LLDB_LOG would greatly simplify this since it puts __FILE__ and __func__ in each message, which is what these are doing manually.

mib added a comment.EditedApr 20 2023, 11:50 AM

I think a lot of this can be simplified by using LLDB_LOG instead of LLDB_LOGF.

+1 to what Jonas said. LLDB_LOG would greatly simplify this since it puts __FILE__ and __func__ in each message, which is what these are doing manually.

@bulbazord @JDevlieghere I don't think using using LLDB_LOG instead of LLDB_LOGF would be of any use here, because we're interested because that will just say we're in Process::__func__. What we care about here is to know which process plugin calling that function, so I still have to pass GetPluginName as an argument.

We'd go from:

LLDB_LOGF(log,
          "Process::SetPrivateState (plugin = %s, state = %s) state didn't "
          "change. Ignoring...",
          GetPluginName().data(), StateAsCString(new_state));

to

LLDB_LOG(log, "(plugin = %s, state = %s) state didn't "
          "change. Ignoring...",
          GetPluginName().data(), StateAsCString(new_state));

LLDB_LOG automatically inserts the file and func into the log. There are plenty of places where we copy/paste logs like these into other files without remembering to update this piece of information, so removing it from the log line entirely helps prevent those kinds of issues in the future. It's a minor thing, but if the point of this patch is to improve the logging mechanism entirely, then I think we should also think about these kinds of things. See 0a74fbb7b1d3e04ac03389f1fc455ac593c2e5ee for an example of what I mean.

mib added a comment.Apr 20 2023, 1:16 PM

We'd go from:

LLDB_LOGF(log,
          "Process::SetPrivateState (plugin = %s, state = %s) state didn't "
          "change. Ignoring...",
          GetPluginName().data(), StateAsCString(new_state));

to

LLDB_LOG(log, "(plugin = %s, state = %s) state didn't "
          "change. Ignoring...",
          GetPluginName().data(), StateAsCString(new_state));

LLDB_LOG automatically inserts the file and func into the log. There are plenty of places where we copy/paste logs like these into other files without remembering to update this piece of information, so removing it from the log line entirely helps prevent those kinds of issues in the future. It's a minor thing, but if the point of this patch is to improve the logging mechanism entirely, then I think we should also think about these kinds of things. See 0a74fbb7b1d3e04ac03389f1fc455ac593c2e5ee for an example of what I mean.

I didn't understand that originally (since what you guys are suggesting doesn't have anything to do with my change), but I'll update it in this patch.

mib updated this revision to Diff 515473.Apr 20 2023, 1:59 PM
mib edited the summary of this revision. (Show Details)

Address @JDevlieghere @bulbazord comments

This revision is now accepted and ready to land.Apr 20 2023, 2:13 PM
This revision was automatically updated to reflect the committed changes.