Log: Fix a regression in handling log options

The channel refactor introduced a regression where we were not honoring
the log options passed when enabling the channel. Fix that and add a
test.

llvm-svn: 296329
This commit is contained in:
Pavel Labath 2017-02-27 11:05:39 +00:00
parent 6ac8403430
commit 88d081b505
3 changed files with 19 additions and 3 deletions

View File

@ -86,7 +86,7 @@ public:
// Calls to Enable and disable need to be serialized externally.
void Enable(Log &log, const std::shared_ptr<llvm::raw_ostream> &stream_sp,
uint32_t flags);
uint32_t options, uint32_t flags);
// Calls to Enable and disable need to be serialized externally.
void Disable(uint32_t flags);

View File

@ -89,9 +89,10 @@ static uint32_t GetFlags(Stream &stream, const ChannelMap::value_type &entry,
void Log::Channel::Enable(Log &log,
const std::shared_ptr<llvm::raw_ostream> &stream_sp,
uint32_t flags) {
uint32_t options, uint32_t flags) {
log.GetMask().Set(flags);
if (log.GetMask().Get()) {
log.GetOptions().Set(options);
log.SetStream(stream_sp);
log_ptr.store(&log, std::memory_order_release);
}
@ -283,7 +284,8 @@ bool Log::EnableLogChannel(
uint32_t flags = categories && categories[0]
? GetFlags(error_stream, *iter, categories)
: iter->second.channel.default_flags;
iter->second.channel.Enable(iter->second.log, log_stream_sp, flags);
iter->second.channel.Enable(iter->second.log, log_stream_sp, log_options,
flags);
return true;
}

View File

@ -130,6 +130,20 @@ TEST_F(LogChannelTest, Enable) {
EXPECT_NE(nullptr, test_channel.GetLogIfAll(FOO | BAR));
}
TEST_F(LogChannelTest, EnableOptions) {
EXPECT_EQ(nullptr, test_channel.GetLogIfAll(FOO));
std::string message;
std::shared_ptr<llvm::raw_string_ostream> stream_sp(
new llvm::raw_string_ostream(message));
StreamString err;
EXPECT_TRUE(Log::EnableLogChannel(stream_sp, LLDB_LOG_OPTION_VERBOSE, "chan",
nullptr, err));
Log *log = test_channel.GetLogIfAll(FOO);
ASSERT_NE(nullptr, log);
EXPECT_TRUE(log->GetVerbose());
}
TEST_F(LogChannelTest, Disable) {
EXPECT_EQ(nullptr, test_channel.GetLogIfAll(FOO));
const char *cat12[] = {"foo", "bar", nullptr};