diff --git a/lldb/source/Host/common/ProcessLaunchInfo.cpp b/lldb/source/Host/common/ProcessLaunchInfo.cpp --- a/lldb/source/Host/common/ProcessLaunchInfo.cpp +++ b/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); diff --git a/lldb/source/Interpreter/OptionValueArgs.cpp b/lldb/source/Interpreter/OptionValueArgs.cpp --- a/lldb/source/Interpreter/OptionValueArgs.cpp +++ b/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(); diff --git a/lldb/test/Shell/Driver/Inputs/dumpargs.c b/lldb/test/Shell/Driver/Inputs/dumpargs.c new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/Driver/Inputs/dumpargs.c @@ -0,0 +1,8 @@ +#include + +int main(int argc, char *argv[]) { + for (int i = 0; i < argc; i++) { + printf("argv[%d] = \"%s\"\n", i, argv[i]); + } + return 0; +} diff --git a/lldb/test/Shell/Driver/TestEmptyArgument.test b/lldb/test/Shell/Driver/TestEmptyArgument.test new file mode 100644 --- /dev/null +++ b/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"