[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
Mon Mar 6 16:09:16 PST 2023
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, clayborg, jingham, mib, jasonmolenda.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
Currently empty arguments are not respected. They are silently dropped
in two places: (1) when extracting them from the target.run-args
setting and (2) when constructing the lldb-argdumper invocation.
(1) is actually a regression from a few years ago. We did not always
drop empty arguments. See 31d97a5c8ab78c619deada0cdb1fcf64021d25dd.
rdar://106279228
Repository:
rG LLVM Github Monorepo
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.502851.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230307/7f3dcb0d/attachment-0001.bin>
More information about the lldb-commits
mailing list