Skip to content

Commit cc0fc35

Browse files
committed
[LLDB] Fix the use of "platform process launch" with no extra arguments
This fixes #62068. After 8d1de7b the following issue appeared: ``` $ ./bin/lldb /tmp/test.o (lldb) target create "/tmp/test.o" Current executable set to '/tmp/test.o' (aarch64). (lldb) platform process launch -s error: Cannot launch '': Nothing to launch ``` Previously would call target->GetRunArguments when there were no extra arguments, so we could find out what target.run-args might be. Once that change started relying on the first arg being the exe, the fact that that call clears the existing argument list caused the bug. Instead, have it set a local arg list and append that to the existing one. Which in this case will just contain the exe name. Since there's no existing tests for this command I've added a new file that covers enough to check this issue. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D153636
1 parent c31eb82 commit cc0fc35

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

lldb/source/Commands/CommandObjectPlatform.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,12 @@ class CommandObjectPlatformProcessLaunch : public CommandObjectParsed {
12071207
if (m_options.launch_info.GetExecutableFile()) {
12081208
Debugger &debugger = GetDebugger();
12091209

1210-
if (argc == 0)
1211-
target->GetRunArguments(m_options.launch_info.GetArguments());
1210+
if (argc == 0) {
1211+
// If no arguments were given to the command, use target.run-args.
1212+
Args target_run_args;
1213+
target->GetRunArguments(target_run_args);
1214+
m_options.launch_info.GetArguments().AppendArguments(target_run_args);
1215+
}
12121216

12131217
ProcessSP process_sp(platform_sp->DebugProcess(
12141218
m_options.launch_info, debugger, *target, error));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Test platform process launch.
3+
"""
4+
5+
from textwrap import dedent
6+
from lldbsuite.test.lldbtest import TestBase
7+
8+
9+
class ProcessLaunchTestCase(TestBase):
10+
NO_DEBUG_INFO_TESTCASE = True
11+
12+
def setup(self):
13+
self.build()
14+
exe = self.getBuildArtifact("a.out")
15+
self.runCmd("file " + exe)
16+
return (exe, self.getBuildArtifact("stdio.log"))
17+
18+
def test_process_launch_no_args(self):
19+
# When there are no extra arguments we just have 0, the program name.
20+
exe, outfile = self.setup()
21+
self.runCmd("platform process launch --stdout {} -s".format(outfile))
22+
self.runCmd("continue")
23+
24+
with open(outfile) as f:
25+
self.assertEqual(dedent("""\
26+
Got 1 argument(s).
27+
[0]: {}
28+
""".format(exe)), f.read())
29+
30+
def test_process_launch_command_args(self):
31+
exe, outfile = self.setup()
32+
# Arguments given via the command override those in the settings.
33+
self.runCmd("settings set target.run-args D E")
34+
self.runCmd("platform process launch --stdout {} -s -- A B C".format(outfile))
35+
self.runCmd("continue")
36+
37+
with open(outfile) as f:
38+
self.assertEqual(dedent("""\
39+
Got 4 argument(s).
40+
[0]: {}
41+
[1]: A
42+
[2]: B
43+
[3]: C
44+
""".format(exe)), f.read())
45+
46+
def test_process_launch_target_args(self):
47+
exe, outfile = self.setup()
48+
# When no arguments are passed via the command, use the setting.
49+
self.runCmd("settings set target.run-args D E")
50+
self.runCmd("platform process launch --stdout {}".format(outfile))
51+
self.runCmd("continue")
52+
53+
with open(outfile) as f:
54+
self.assertEqual(dedent("""\
55+
Got 3 argument(s).
56+
[0]: {}
57+
[1]: D
58+
[2]: E
59+
""".format(exe)), f.read())
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char const *argv[]) {
4+
printf("Got %d argument(s).\n", argc);
5+
for (int i = 0; i < argc; ++i)
6+
printf("[%d]: %s\n", i, argv[i]);
7+
return 0;
8+
}

0 commit comments

Comments
 (0)