[Lldb-commits] [PATCH] D145450: [lldb] Respect empty arguments in target.run-args

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 7 11:29:44 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGca8faf8f4659: [lldb] Respect empty arguments in target.run-args (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145450/new/

https://reviews.llvm.org/D145450

Files:
  lldb/source/Host/common/ProcessLaunchInfo.cpp
  lldb/source/Interpreter/OptionValueArgs.cpp
  lldb/test/Shell/Driver/Inputs/dumpargs.c
  lldb/test/Shell/Driver/TestEmptyArgument.test


Index: lldb/test/Shell/Driver/TestEmptyArgument.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Driver/TestEmptyArgument.test
@@ -0,0 +1,7 @@
+# RUN: %clang_host %S/Inputs/dumpargs.c -o %t.out
+# RUN: %lldb -b -o "r" %t.out -- "one" "two" "" "three" | FileCheck %s
+
+# CHECK: argv[1] = "one"
+# CHECK: argv[2] = "two"
+# CHECK: argv[3] = ""
+# CHECK: argv[4] = "three"
Index: lldb/test/Shell/Driver/Inputs/dumpargs.c
===================================================================
--- /dev/null
+++ lldb/test/Shell/Driver/Inputs/dumpargs.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+  for (int i = 0; i < argc; i++) {
+    printf("argv[%d] = \"%s\"\n", i, argv[i]);
+  }
+  return 0;
+}
Index: lldb/source/Interpreter/OptionValueArgs.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueArgs.cpp
+++ lldb/source/Interpreter/OptionValueArgs.cpp
@@ -17,8 +17,7 @@
   args.Clear();
   for (const auto &value : m_values) {
     llvm::StringRef string_value = value->GetStringValue();
-    if (!string_value.empty())
-      args.AppendArgument(string_value);
+    args.AppendArgument(string_value);
   }
 
   return args.GetArgumentCount();
Index: lldb/source/Host/common/ProcessLaunchInfo.cpp
===================================================================
--- lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -321,6 +321,8 @@
       } else {
         for (size_t i = 0; argv[i] != nullptr; ++i) {
           std::string safe_arg = Args::GetShellSafeArgument(m_shell, argv[i]);
+          if (safe_arg.empty())
+            safe_arg = "\"\"";
           // Add a space to separate this arg from the previous one.
           shell_command.PutCString(" ");
           shell_command.PutCString(safe_arg);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145450.503112.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230307/f7c43274/attachment-0001.bin>


More information about the lldb-commits mailing list