puremourning / vimspector

vimspector - A multi-language debugging system for Vim
http://puremourning.github.io/vimspector-web
Apache License 2.0
4.08k stars 171 forks source link

`Vimspector not connected error` on fresh install #828

Closed xave closed 7 months ago

xave commented 7 months ago

Description

On a fresh plugin install with

vim -Nu /the/path/to/my/install/vimspector/tests/vimrc --cmd "let g:vimspector_enable_mappings='HUMAN'" tiny.c

in the directory /path/to/install/vimspector/support/test/cpp/tiny_c after hitting F5, installing the gadget, choosing a debug confguration from one of the three preconfigured ones, and then trying to set a breakpoint, choosing an error flashes.

Vimspector not connected, start a debug session first

Is it reproducible in vim?

Reproducible in Vim

Works with clean config?

Yes

Sample project works?

Reproducible with sample project

Minimal Reproduction

See above.

Expected Behaviour

Expected behavior is that the debug session would start as soon as I choose the debug configuration, as per the docs.

Actual Behaviour

No debugging of the program itself occurs.

Additional information

I find it a bit suspicious that the sample .vimspector.json in the tiny.c has a hardcoded path $Home/Developer/foo/bar as that is not standard and is thus specialized to one person's workflow. Regardless, changing that path does not allow this plugin to function.

Installation Type

Vim packages (git clone)

Vimspector version

703df4d948957105fe056dec9b106fbebf25ca66

Debug Info

Vimspector not connected, start a debug session first

Which launch configuration?
1: CodeLLDB <----------------------------------------[selected 1]---------------------------------
2: cpptools (gdb)
3: cpptools (lldb)
Connecting to 127.0.0.1:58975... (waiting for up to 10 seconds)
Error detected while processing function vimspector#Continue[4]..function vimspector#Continue:
line    4:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 60, in wrapper
    return fct( active_session, *args, **kwargs )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 867, in Continue
    self.Start()
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 71, in wrapper
    return fct( self, *args, **kwargs )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 475, in Start
    self._StartWithConfiguration( configuration, adapter )
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 520, in _StartWithConfiguration
    start()
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 506, in start
    if not self._StartDebugAdapter():
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 1459, in _StartDebugAdapter
    if not vim.eval( "vimspector#internal#{}#StartDebugSession( "
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
vim.error: Vim(let):E902: Cannot connect to port: Can't assign requested address

Log file

2024-01-19 07:21:27,262 - INFO - debug_session.py:128 - 0 - **** INITIALISING NEW VIMSPECTOR SESSION FOR ID 0 ****
2024-01-19 07:21:27,262 - INFO - debug_session.py:130 - 0 - API is: 
2024-01-19 07:21:27,263 - INFO - debug_session.py:131 - 0 - VIMSPECTOR_HOME = /Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/../..
2024-01-19 07:21:27,263 - INFO - debug_session.py:132 - 0 - gadgetDir = /Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/gadgets/macos
2024-01-19 07:21:27,263 - INFO - debug_session.py:226 - 0 - User requested start debug session with {}
2024-01-19 07:21:27,263 - DEBUG - debug_session.py:187 - 0 - Reading configurations from: None
2024-01-19 07:21:27,263 - DEBUG - debug_session.py:187 - 0 - Reading configurations from: /Users/bazbar/.dotfiles/vim/pack/foobar-plugins/start/vimspector/support/test/cpp/tiny_c/.vimspector.json
2024-01-19 07:21:27,265 - DEBUG - debug_session.py:250 - 0 - Reading gadget config: /Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/gadgets/macos/.gadgets.json
2024-01-19 07:21:27,266 - DEBUG - debug_session.py:250 - 0 - Reading gadget config: None
2024-01-19 07:21:31,090 - DEBUG - utils.py:633 - None - Returning workspaceRoot from the map for workspaceRoot with args ()
2024-01-19 07:21:31,090 - DEBUG - utils.py:633 - None - Returning gadgetDir from the map for gadgetDir with args ()
2024-01-19 07:21:31,090 - DEBUG - utils.py:633 - None - Returning workspaceRoot from the map for workspaceRoot with args ()
2024-01-19 07:21:31,090 - INFO - debug_session.py:483 - 0 - Configuration: {"adapter": "custom-cpptools", "configuration": {"request": "launch", "program": "/Users/bazbar/.dotfiles/vim/pack/foobar-plugins/start/vimspector/support/test/cpp/tiny_c/tiny", "stopAtEntry": true, "MIMode": "lldb", "MIDebuggerPath": "/Users/bazbar/.vim/pack/foobar-plugins/start/vimspector/gadgets/macos/vscode-cpptools/debugAdapters/lldb-mi/bin/lldb-mi", "logging": {"engineLogging": true}}}
2024-01-19 07:21:31,090 - INFO - debug_session.py:485 - 0 - Adapter: {"attach": {"pidProperty": "processId", "pidSelect": "ask"}, "command": ["/Users/bazbar/Development/vimspector/MIEngine/bin/Debug/vscode/OpenDebugAD7"], "configuration": {"args": [], "cwd": "/Users/bazbar/.dotfiles/vim/pack/foobar-plugins/start/vimspector/support/test/cpp/tiny_c", "environment": [], "type": "cppdbg"}, "name": "cppdbg"}
2024-01-19 07:21:31,091 - DEBUG - debug_session.py:1201 - 0 - min_width/height: 149/50, actual: 178/47 - result: horizontal
2024-01-19 07:21:31,124 - DEBUG - debug_session.py:1785 - 0 - LAUNCH!
2024-01-19 07:21:31,127 - INFO - debug_session.py:1400 - 0 - Starting debug adapter with: {"attach": {"pidProperty": "processId", "pidSelect": "ask"}, "command": ["/Users/bazbar/Development/vimspector/MIEngine/bin/Debug/vscode/OpenDebugAD7"], "configuration": {"args": [], "cwd": "/Users/bazbar/.dotfiles/vim/pack/foobar-plugins/start/vimspector/support/test/cpp/tiny_c", "environment": [], "type": "cppdbg"}, "name": "cppdbg"}
2024-01-19 07:21:31,127 - DEBUG - debug_session.py:1419 - 0 - Connection Type: job
2024-01-19 07:21:31,131 - INFO - debug_session.py:1503 - 0 - Debug Adapter Started
2024-01-19 07:21:31,131 - DEBUG - debug_adapter_connection.py:205 - 0 - Sending Message: {"command": "initialize", "arguments": {"adapterID": "cppdbg", "clientID": "vimspector", "clientName": "vimspector", "linesStartAt1": true, "columnsStartAt1": true, "locale": "en_GB", "pathFormat": "path", "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true, "supportsMemoryReferences": true, "supportsStartDebuggingRequest": true}, "seq": 0, "type": "request"}
2024-01-19 07:21:31,131 - INFO - debug_session.py:2047 - 0 - The server has terminated with status 122
2024-01-19 07:21:31,131 - DEBUG - debug_adapter_connection.py:162 - 0 - Closing down: Aborting request {'command': 'initialize', 'arguments': {'adapterID': 'cppdbg', 'clientID': 'vimspector', 'clientName': 'vimspector', 'linesStartAt1': True, 'columnsStartAt1': True, 'locale': 'en_GB', 'pathFormat': 'path', 'supportsVariableType': True, 'supportsVariablePaging': False, 'supportsRunInTerminalRequest': True, 'supportsMemoryReferences': True, 'supportsStartDebuggingRequest': True}, 'seq': 0, 'type': 'request'}
2024-01-19 07:21:31,133 - DEBUG - debug_session.py:2070 - 0 - No server exit handler

Vim version

vim 9.0.2116

Python version

3.11.6 (main, Oct 2 2023, 13:45:54) [Clang 16.0.6]

Neovim diagnostics

No response

Operating System

macOS arm64

Declaration

puremourning commented 7 months ago

So I understand, your issue is specifically with the test? Well the actual regression tests in ci use this so I’m certain it works. My guess is you didn’t compile the test binary or something (it’s not noted in your repro step)

the error from the adapter is:

2024-01-19 07:21:31,131 - INFO - debug_session.py:2047 - 0 - The server has terminated with status 122

puremourning commented 7 months ago

Sorry I misunderstood. You seem to be trying to launch a test from the tests dir and this is set up to use a debug adapter ‘custom-cpptools’ which is hard coded to a path that won’t exist on your system.

You are likely better off trying the other tests in tests/testdata/cpp/simple as these are the ones used in CI.

Or test your own project of course.

xave commented 7 months ago

I have tried other directories as well and get similar errors. Ultimately, that the debug does not work. The instructions on the main page of this website point one to the very directories you have told me not to use.

Also, I tried the vim debug tutorial verbatim and that also did not work. There might be a subtle python3 bug.

xave commented 7 months ago

From the main page of the repo:

Trying it out

If you just want to try out vimspector without changing your vim config, there are example projects for a number of languages in support/test, including:

Python (support/test/python/simple_python) Go (support/test/go/hello_world and support/test/go/name-starts-with-vowel) Nodejs (support/test/node/simple) Chrome/Firefox (support/test/web/) etc. To test one of these out, cd to the directory and run:

vim -Nu /path/to/vimspector/tests/vimrc --cmd "let g:vimspector_enable_mappings='HUMAN'" Then press \<F5>.

There's also a C++ project in tests/testdata/cpp/simple/ with a Makefile which can be used to check everything is working. This is used by the regression tests in CI so should always work, and is a good way to check if the problem is your configuration rather than a bug.

I did exactly this.

xave commented 7 months ago

Also, I did compile the test binary

clang -g -o tiny tiny.c
xave commented 7 months ago

Ultimately, I am looking for a simple clang setup to test on a minimal project. I have read through the entire manual and have tried various combinations of things, which if I had to detail in the level that I detailed this one attempt would create a very long post. I think there should be a minimal, no-frills working example to be run in the repo.

I'm thinking it should use CodeLLDB as you have recommended with no "extensions". Just a simple, local compiling option that uses directory setups that most people would use by default. Then people can use the other examples to make a more complicated version.

Everything I have tried thus far, to include modifying paths, trying various sample c.json and .vimspector.json, setting gadget directory, not setting it and letting it install into the plugin repo. They all result in the same outcome. Vim errors and no working debugger.

I have verified that I can debug with pure lldb so it is not that I don't have a working debugger at all. How many arm64 macOS users do you have? Things vary subtly between that and Linux.

Because these minimal examples do not work on a clean install, it is difficult to try out the remaining concepts and functionality. This seems like a bug to me.

puremourning commented 7 months ago

I use macOS arm64 so I’m confident that it works.

puremourning commented 7 months ago

Here's some "proof" - me doing it on arm64 Mac from clean install.

xave commented 7 months ago

What files are you using for that example?

I have .vimspector.json

{
  "configurations": {
    "launch": {
      "adapter": "CodeLLDB",
      "filetypes": [ "rust", "c" , "cpp" ],
      "configuration": {
        "request": "launch",
        "program": "${workspaceRoot}/${fileBasenameNoExtension}"
      }
    },
    "attach": {
      "adapter": "CodeLLDB",
      "filetypes": [ "rust", "c", "cpp", "jai" ],
      "configuration": {
        "request": "attach",
        "program": "${workspaceRoot}/${fileBasenameNoExtension}",
        "PID": "${PID}"
      }
    }
  }
}

For this dir structure:

tiny_c/
├── .vimspector.json
├── tiny
└── tiny.c
xave commented 7 months ago

Have you needed to do anything to set Python?

I have also gotten lots of Python-related errors such as messages starting with:

File "<string>", line 1, in <module>

and messages that are variations on:

Error detected while processing function vimspector#Launch:
line    4:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/barbaz/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 71, in wrapper
    return fct( self, *args, **kwargs )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/barbaz/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 239, in Start
    all_configurations ) = self.GetConfigurations( adapters )
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/barbaz/.vim/pack/foobar-plugins/start/vimspector/python3/vimspector/debug_session.py", line 192, in GetConfigurations
    database = json.loads( minify( f.read() ) )
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/z0nnwdh4p692yvf3qgwgj3bn78w99q6y-python3-3.11.6/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/z0nnwdh4p692yvf3qgwgj3bn78w99q6y-python3-3.11.6/lib/python3.11/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 17 (char 16)

I have python3 installed globally via nix. My vim is +python3.

EDIT: Just installed python3Full. No change to behavior. It is 3.11.6.

xave commented 7 months ago

To add some information:

I can get the workspace UI to show up and I can toggle breakpoints. Something with actually doing the debugging part is not working for me.

xave commented 7 months ago

I am often getting errors about not being able to connect to a port, which I don't think I need to do unless I make a .json asking for one, and it seems that you have a handy thing that searches for open ports automatically. Many examples use that functionality when they use it at all.

From your second video, I get the "Connecting... Waiting 10 seconds" message, then immediately error messages.

xave commented 7 months ago

Occasionally, errors with text including

Error detected while processing function 
...
File "<string>", line 1, in <module>

point to plugin clashing. I uninstalled all plugins except this one and they persist.


Switching gears a bit...

Error E902 in vim -- https://vimhelp.org/channel.txt.html

When the channel can't be opened you will get an error message. There is a difference between MS-Windows and Unix: On Unix when the port doesn't exist ch_open() fails quickly. On MS-Windows "waittime" applies. E898 E901 E902

xave commented 7 months ago

Did some more sleuthing using the code from here.

CodeLLDB is the thing giving issues. The following is placed into the vimspector base directory:

in .vimrc

let g:vimspector_base_dir=expand( '$HOME/.vim/vimspector-config' )

in ${HOME}/.vim/vimspector-config/configurations/<os>/c/c.json

This c.json works (using vscode-cpptools):

  "configurations": {
    "C": {
      // Local C debugging
      "adapter": "vscode-cpptools",
      "configuration": {
        "request": "launch",
        "program": "${workspaceRoot}/${fileBasenameNoExtension}",
        "StopAtEntry": true,
        "MIMode": "lldb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for lldb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      }
    }

This c.json does not work (using CodeLLDB) and gives the errors mentioned in this BUG REPORT:

    "C-CodeLLDB": {
      // Local C debugging
      "adapter": "CodeLLDB",
      "configuration": {
        "request": "launch",
        "program": "${workspaceRoot}/${fileBasenameNoExtension}",
        "StopAtEntry": true,
        "MIMode": "lldb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for lldb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      }
    }