Skip to content

Commit 3c565c2

Browse files
committed
[lldb] Print an error for unsupported combinations of log options
Print an error for unsupported combinations of log handlers and log options. Only the stream log handler takes a file and only the circular and stream handler take a buffer size. This cannot be dealt with through option groups because the option combinations depend on the requested handler. Differential revision: https://reviews.llvm.org/D143623
1 parent 08b1708 commit 3c565c2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lldb/source/Commands/CommandObjectLog.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ class CommandObjectLogEnable : public CommandObjectParsed {
177177
return false;
178178
}
179179

180+
if ((m_options.handler != eLogHandlerCircular &&
181+
m_options.handler != eLogHandlerStream) &&
182+
m_options.buffer_size.GetCurrentValue() != 0) {
183+
result.AppendError("a buffer size can only be specified for the circular "
184+
"and stream buffer handler.\n");
185+
return false;
186+
}
187+
188+
if (m_options.handler != eLogHandlerStream && m_options.log_file) {
189+
result.AppendError(
190+
"a file name can only be specified for the stream handler.\n");
191+
return false;
192+
}
193+
180194
// Store into a std::string since we're about to shift the channel off.
181195
const std::string channel = std::string(args[0].ref());
182196
args.Shift(); // Shift off the channel

lldb/test/Shell/Log/TestHandlers.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# RUN: %lldb -o 'log enable --log-handler os --file /tmp/foo gdb-remote packets' 2>&1 | FileCheck %s --check-prefix UNSUPPORTED-FILE
2+
# RUN: %lldb -o 'log enable --log-handler os --buffer 10 gdb-remote packets' 2>&1 | FileCheck %s --check-prefix UNSUPPORTED-BUFFER
3+
4+
# UNSUPPORTED-FILE: a file name can only be specified for the stream handler
5+
# UNSUPPORTED-BUFFER: a buffer size can only be specified for the circular and stream buffer handler

0 commit comments

Comments
 (0)