Skip to content

Commit 7bcc4ba

Browse files
committed
Fix review comments
1 parent 4c3e009 commit 7bcc4ba

File tree

4 files changed

+66
-38
lines changed

4 files changed

+66
-38
lines changed

lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,13 @@ def test_stdio_redirection(self):
630630
"""
631631
Test stdio redirection.
632632
"""
633-
temp_file = tempfile.NamedTemporaryFile().name
634633
self.build_and_create_debug_adapter()
635634
program = self.getBuildArtifact("a.out")
636635

637-
self.launch(program, stdio=[None, temp_file, None])
638-
self.continue_to_exit()
639-
640-
try:
641-
with open(temp_file, "r") as f:
642-
lines = f.readlines()
643-
self.assertIn(
644-
program, lines[0], "make sure program path is in first argument"
645-
)
646-
finally:
647-
pathlib.Path(temp_file).unlink(missing_ok=True)
636+
with tempfile.NamedTemporaryFile("rt") as f:
637+
self.launch(program, stdio=[None, f.name, None])
638+
self.continue_to_exit()
639+
lines = f.readlines()
640+
self.assertIn(
641+
program, lines[0], "make sure program path is in first argument"
642+
)

lldb/tools/lldb-dap/Handler/RequestHandler.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ static uint32_t SetLaunchFlag(uint32_t flags, bool flag,
5151
return flags;
5252
}
5353

54+
static void
55+
SetupIORedirection(const std::vector<std::optional<std::string>> &stdio,
56+
lldb::SBLaunchInfo &launch_info) {
57+
size_t n = std::max(stdio.size(), static_cast<size_t>(3));
58+
for (size_t i = 0; i < n; i++) {
59+
std::optional<std::string> path;
60+
if (stdio.size() < i)
61+
path = stdio.back();
62+
else
63+
path = stdio[i];
64+
if (!path)
65+
continue;
66+
switch (i) {
67+
case 0:
68+
launch_info.AddOpenFileAction(i, path->c_str(), true, false);
69+
break;
70+
case 1:
71+
case 2:
72+
launch_info.AddOpenFileAction(i, path->c_str(), false, true);
73+
break;
74+
default:
75+
launch_info.AddOpenFileAction(i, path->c_str(), true, true);
76+
break;
77+
}
78+
}
79+
}
80+
5481
static llvm::Error
5582
RunInTerminal(DAP &dap, const protocol::LaunchRequestArguments &arguments) {
5683
if (!dap.clientFeatures.contains(
@@ -177,30 +204,8 @@ llvm::Error BaseRequestHandler::LaunchProcess(
177204
launch_info.SetEnvironment(env, true);
178205
}
179206

180-
if (!arguments.stdio.empty() && !arguments.disableSTDIO) {
181-
size_t n = std::max(arguments.stdio.size(), static_cast<size_t>(3));
182-
for (size_t i = 0; i < n; i++) {
183-
std::optional<std::string> path;
184-
if (arguments.stdio.size() < i)
185-
path = arguments.stdio.back();
186-
else
187-
path = arguments.stdio[i];
188-
if (!path)
189-
continue;
190-
switch (i) {
191-
case 0:
192-
launch_info.AddOpenFileAction(i, path->c_str(), true, false);
193-
break;
194-
case 1:
195-
case 2:
196-
launch_info.AddOpenFileAction(i, path->c_str(), false, true);
197-
break;
198-
default:
199-
launch_info.AddOpenFileAction(i, path->c_str(), true, true);
200-
break;
201-
}
202-
}
203-
}
207+
if (!arguments.stdio.empty() && !arguments.disableSTDIO)
208+
SetupIORedirection(arguments.stdio, launch_info);
204209

205210
launch_info.SetDetachOnError(arguments.detachOnError);
206211
launch_info.SetShellExpandArguments(arguments.shellExpandArguments);

lldb/tools/lldb-dap/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ adds `FOO=1` and `bar` to the environment:
4444
}
4545
```
4646

47+
#### Launch in integrated terminal
48+
49+
This will launch process in IDE's integrated terminal.
50+
51+
```javascript
52+
{
53+
"type": "lldb-dap",
54+
"request": "launch",
55+
"name": "Debug",
56+
"program": "/tmp/a.out",
57+
"console": "integratedTerminal"
58+
}
59+
```
60+
61+
#### Setup IO redirection
62+
63+
This will launch process and connect `stdin` to `in.txt`, both of `stdout` and `stderr` to `out.txt`.
64+
65+
```javascript
66+
{
67+
"type": "lldb-dap",
68+
"request": "launch",
69+
"name": "Debug",
70+
"program": "/tmp/a.out",
71+
"stdio": ["in.txt", "out.txt"]
72+
}
73+
```
74+
4775
### Attaching to a process
4876

4977
When attaching to a process using LLDB, you can attach in multiple ways:
@@ -237,7 +265,7 @@ contain the following key/value pairs:
237265
| **stopOnEntry** | boolean | | Whether to stop program immediately after launching.
238266
| **runInTerminal** (deprecated) | boolean | | Launch the program inside an integrated terminal in the IDE. Useful for debugging interactive command line programs.
239267
| **console** | string | | Specify where to launch the program: internal console (`internalConsole`), integrated terminal (`integratedTerminal`) or external terminal (`externalTerminal`). Supported from lldb-dap 21.0 version.
240-
| **stdio** | [string] | | Destination for program stdio streams (0 - stdin, 1 - stdout, 2 - stderr, ...). Using `null` value means no redirection. Supported from lldb-dap 22.0 version.
268+
| **stdio** | [string] | | The stdio property specifies the redirection targets for the debuggee's stdio streams. A null value redirects a stream to the default debug terminal. String can be a path to file, named pipe or TTY device. If less than three values are provided, the list will be padded with the last value. Specifying more than three values will create additional file descriptors (4, 5, etc.). Supported from lldb-dap 22.0 version.
241269
| **launchCommands** | [string] | | LLDB commands executed to launch the program.
242270

243271
For JSON configurations of `"type": "attach"`, the JSON configuration can contain

lldb/tools/lldb-dap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@
620620
"items": {
621621
"type": "string"
622622
},
623-
"description": "Destination for program stdio streams (0 - stdin, 1 - stdout, 2 - stderr, ...). Using null value means no redirection.",
623+
"description": "The stdio property specifies the redirection targets for the debuggee's stdio streams. A null value redirects a stream to the default debug terminal. String can be a path to file, named pipe or TTY device. If less than three values are provided, the list will be padded with the last value. Specifying more than three values will create additional file descriptors (4, 5, etc.).",
624624
"default": []
625625
},
626626
"timeout": {

0 commit comments

Comments
 (0)