Skip to content

Commit

Permalink
Log: Fix a regression in handling log options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
labath committed Feb 27, 2017
1 parent 6ac8403 commit 88d081b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/Log.h
Expand Up @@ -86,7 +86,7 @@ class Log final {

// 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);
Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Core/Log.cpp
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions lldb/unittests/Core/LogTest.cpp
Expand Up @@ -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};
Expand Down

0 comments on commit 88d081b

Please sign in to comment.