Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exit code 1 warning at the end of a debug session on Windows #969

Merged
merged 4 commits into from
Sep 14, 2023

Conversation

Aeceon
Copy link
Contributor

@Aeceon Aeceon commented Jun 10, 2023

On Windows, when using a server type debug adapter that is executed (in this case codelldb) I received the following warning after a debug session ended:

...codelldb.CMD exited with code 1

Changing "sigterm" to "SIGTERM" in the client close function fixes this.

…en using a server type debug adapter that is executed.
@Aeceon
Copy link
Contributor Author

Aeceon commented Jun 10, 2023

I've jumped the gun here. I should have opened an issue first.

After receiving the exit code 1 warning, I read the Neovim documentation on kill and noticed that sigterm was in uppercase here. I made this change and the debug adapter correctly exited with code 0. I should have looked into it further because It correctly exits with code 0 on Windows for everything but "sigterm" (lowercase). For instance:

handle:kill("blah")

This sees the debug adapter exit with code 0 as well.

Steps to reproduce the original issue on Windows (not WSL):

  1. The following adapter configuration automatically provided by mason-nvim-dap:
local dap = require('dap')

dap.adapters.codelldb = {
	type = 'server',
	port = '${port}',
	executable = {
		command = vim.fn.exepath('codelldb'),
		args = { '--port', '${port}' },
	},
}

if vim.fn.has('win32') == 1 then
	dap.adapters.codelldb.executable.detached = false
end

dap.configurations.cpp = {
  {
    name = 'Launch',
    type = 'codelldb',
    request = 'launch',
    program = function()
      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
    end,
    cwd = '${workspaceFolder}',
    stopOnEntry = false,
    args = {},
}

dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp
  1. Compile a standard hello world program in C with MSVC ("cl /Zi main.c").
  2. Open the hello world source file in Neovim.
  3. Set a breakpoint before print.
  4. Start a debug session with the compiled program.
  5. Hit continue once the breakpoint has been reached.

I then receive the following warning when the debug session ends (generated on line 1152 of session.lua):

...codelldb.CMD exited with code 1

This doesn't happen if handle:kill is passed anything other than "sigterm" (lowercase).

@mfussenegger
Copy link
Owner

Could you try with sigint ?

Changing it to SIGTERM prevents it from terminating the process on linux, and it again leaks processes if they don't stop by themselves after a debug session (which vscode-js-debug doesn't).

@mfussenegger
Copy link
Owner

@Aeceon did you have a chance to try with sigint?

@Aeceon
Copy link
Contributor Author

Aeceon commented Aug 8, 2023

Sorry, I forgot I hadn't updated this. sigint gave the same "exited with code 1" error. sighup, however, works. I changed the code to only use this on Windows and stick to sigterm otherwise.

@mfussenegger mfussenegger merged commit b3d4408 into mfussenegger:master Sep 14, 2023
4 checks passed
@Aeceon Aeceon deleted the fix-exit-code-1-server-types branch September 20, 2023 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants