mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support stdio redirection with lldb-vscode

bagel897 opened this issue · comments

Problem Statement

I want to redirect stdio to read from file to debug a c++ program without making a specific configuration or program per file.

Ideas or possible solutions

https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#stdio-redirection
LLDB-vscode supports stdio redirection.
Perhaps nvim-dap could support it?

Did you try using the options?

Yes, using the stdio option in the configuration doesn't work in nvim-dap but does work in vscode.

launch.json:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "test1",
			"type": "lldb",
			"request": "launch",
			"program": "${workspaceFolder}/cpp.out",
			"stdio": [
				"${workspaceFolder}/input1",
				null, null
			]
		}
	]
}

Works fine for me with this config:

    {
      name = "Launch via codelldb",
      type = "codelldb",
      request = "launch",
      program = function()
        return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
      end,
      stdio = {"input.txt", nil, nil},
      cwd = '${workspaceFolder}',
      args = {},
    },
recording.mp4

Trying the configuration you provided works for codelldb (from the .vsix) but not for lldb-vscode (from native package manager, version 13.0.1). I'm using lldb 13 locally.
The codelldb version uses a function so the function we define in the config is called on adapter start.
But for the lldb-vscode version, the apater configuration is a table, which calls the following code:

  local spawn_opts = {
    args = adapter.args;
    stdio = {stdin, stdout, stderr};
    cwd = options.cwd;
    env = options.env;
}

in the function Session:spawn.
So we need a way to pass the stdio options stdio into the spawn_opts for stdio and use their defaults for nil values.

lldb-vscode is a different debug adapter than codelldb. The documentation you linked is for codelldb, not lldb-vscode. As far as I am aware lldb-vscode doese not support stdio redirection the way codelldb does.

So we need a way to pass the stdio options stdio into the spawn_opts for stdio and use their defaults for nil values.

No we don't. spawn launches the debug adapter and stdio is used for the dap client to communicate with the debug adapter. This is not the same as stdio handling for your application - the debuggee
Spawning the debugee is handled by the debug adapter (or optionally indirectly by nvim-dap via the integrated terminal, but that is also controlled by the debug adapter)

Hi, I had the same issue, you can use stdin with lldb-vscode. Just add
preRunCommands= {'settings set target.input-path <file>'}