[Lldb-commits] [lldb] 3c565c2 - [lldb] Print an error for unsupported combinations of log options

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 9 09:58:48 PST 2023


Author: Jonas Devlieghere
Date: 2023-02-09T09:58:39-08:00
New Revision: 3c565c246635cace81f01340cd3d1d7386042478

URL: https://github.com/llvm/llvm-project/commit/3c565c246635cace81f01340cd3d1d7386042478
DIFF: https://github.com/llvm/llvm-project/commit/3c565c246635cace81f01340cd3d1d7386042478.diff

LOG: [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

Added: 
    lldb/test/Shell/Log/TestHandlers.test

Modified: 
    lldb/source/Commands/CommandObjectLog.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp
index c63d8ce4f9e40..8549d22e70f98 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -177,6 +177,20 @@ class CommandObjectLogEnable : public CommandObjectParsed {
       return false;
     }
 
+    if ((m_options.handler != eLogHandlerCircular &&
+         m_options.handler != eLogHandlerStream) &&
+        m_options.buffer_size.GetCurrentValue() != 0) {
+      result.AppendError("a buffer size can only be specified for the circular "
+                         "and stream buffer handler.\n");
+      return false;
+    }
+
+    if (m_options.handler != eLogHandlerStream && m_options.log_file) {
+      result.AppendError(
+          "a file name can only be specified for the stream handler.\n");
+      return false;
+    }
+
     // Store into a std::string since we're about to shift the channel off.
     const std::string channel = std::string(args[0].ref());
     args.Shift(); // Shift off the channel

diff  --git a/lldb/test/Shell/Log/TestHandlers.test b/lldb/test/Shell/Log/TestHandlers.test
new file mode 100644
index 0000000000000..3cf900888bb22
--- /dev/null
+++ b/lldb/test/Shell/Log/TestHandlers.test
@@ -0,0 +1,5 @@
+# RUN: %lldb -o 'log enable --log-handler os --file /tmp/foo  gdb-remote packets' 2>&1 | FileCheck %s  --check-prefix UNSUPPORTED-FILE
+# RUN: %lldb -o 'log enable --log-handler os --buffer 10  gdb-remote packets' 2>&1 | FileCheck %s  --check-prefix UNSUPPORTED-BUFFER
+
+# UNSUPPORTED-FILE: a file name can only be specified for the stream handler
+# UNSUPPORTED-BUFFER:  a buffer size can only be specified for the circular and stream buffer handler


        


More information about the lldb-commits mailing list