mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.46k stars 194 forks source link

Native GDB DAP unable to run #1206

Closed ibsil closed 4 months ago

ibsil commented 5 months ago

Debug adapter definition and debug configuration

I have installed nvim-dap, and nvim-dap-ui and GDB 14.2 which should have DAP included. I have also written a simple C program main.c for testing that nvim-dap is working as expected.

// main.c
#include "stdio.h"
int main(){
int x = 0;
x = x+1;
printf("%d",x);
}

In my init.lua I have written the dap configuration as follows:

require('dap').adapters.gdb = {
  type = "executable",
  command = "gdb",
  args = { "-i", "dap" }
}
require('dap').configurations.c = {
  {
    name = "Launch",
    type = "gdb",
    request = "launch",
    program = function()
      return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
    end,
    cwd = "${workspaceFolder}",
    stopAtBeginningOfMainSubprogram = false,
  },
}
require("dapui").setup()

The program main.c compiles and runs without issue.

Debug adapter version

No response

Steps to Reproduce

  1. Compile main.c with gcc -ggdb main.c -o main
  2. Open main.c and call :DapContinue, specify path to executable main
  3. Errors can be seen in REPL with :DapToggleRepl

Expected Result

Expected dap-ui to bring up windows used to aid in debugging the program (program state, function call stack, expression watching, breakpoints, etc.)

Actual Result

GNU gdb (GDB) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
1Exception in thread DAP:
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/share/gdb/python/gdb/dap/startup.py", line 51, in really_start_dap
    target()
  File "/usr/share/gdb/python/gdb/dap/startup.py", line 73, in ensure_dap_thread
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/gdb/python/gdb/dap/server.py", line 117, in main_loop
    cmd = read_json(self.in_stream)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/gdb/python/gdb/dap/io.py", line 37, in read_json
    while len(data) < content_length:
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'int' and 'NoneType'
curtishd commented 5 months ago

I reproduce the issue, gdb shows rollout code as 1.

kkcarlc commented 4 months ago

I can also confirm that I have this same issue. Not using nvim-dap-ui.

gcc (GCC) 13.2.1 20240417 Python 3.12.3 pynvim 0.5.0

mfussenegger commented 4 months ago

Sounds like a duplicate of https://github.com/mfussenegger/nvim-dap/issues/1150 ?

Note that the error is printed when the debug session exits, and it stops fine at breakpoints and so on.

kkcarlc commented 4 months ago

@mfussenegger You are right. Thanks for answering.

You can disregard my comment since I was using a non supported version of gcc (13.2) and was not getting breakpoints which I wrongly correlated with the above message. I updated to gcc 14.1 today and it is indeed hitting breakpoints and the message printed is after the session exits as you stated.

mfussenegger commented 4 months ago

Changed the process shutdown logic a bit (https://github.com/mfussenegger/nvim-dap/pull/1210). It now closes the stdio handles after the process has exited, instead of doing that a bit earlier. That gets rid of the error messages in the repl.

kkcarlc commented 4 months ago

Thanks @mfussenegger I have confirmed the fix.