This is an archive of the discontinued LLVM Phabricator instance.

[lldb/test][TestingSupport] Add a helper class to send all LLDB logs to stderr in unit tests.
Needs ReviewPublic

Authored by rupprecht on Sep 9 2022, 7:20 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This helper class can be useful to see what LLDB_LOG messages are happening when debugging the LLDB C++ unit tests. It isn't pretty, but on the other hand, it's meant for temporary debugging and not something one would want to check in anyway, so maybe that's OK.

This can be used like so:

TEST(FooTest, HasABug) {
  Func1(); // LLDB_LOG statements this makes won't go anywhere
  {
    auto logger = TestStderrLogger::Scoped(LLDBLog::AST | LLDBLog::Breakpoints);
    Func2(); // Now they'll go to stderr.
  }
  Func3(); // Now they go nowhere again.
}

It can be created in a way that mirrors GetLog() calls, i.e. deducing from the enum, or by directly using the strings that are registered.

Right now this only works for the LLDBLog enum, but it should be trivial to add more. I don't know of a good generic way to handle arbitrary enums.

I was able to use this to debug a flaky unit test that was failing ~1/100 times, so my approach was to enable logs and compare good vs bad log methods. I didn't find an easier way than this helper class.

Diff Detail

Event Timeline

rupprecht created this revision.Sep 9 2022, 7:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 7:20 PM
Herald added a subscriber: mgorny. · View Herald Transcript
rupprecht requested review of this revision.Sep 9 2022, 7:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 7:20 PM