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.