mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attempt to index local 'frame' (a number value)

asmodeus812 opened this issue · comments

Debug adapter definition and debug configuration

adapter = function(callback, config)
        callback({ type = "server", host = '127.0.0.1', port = 13000 })
end,
configurations = {
        default_launch = {
            type = "lldb",
            request = "launch",
            name = "Default launch (codelldb)",
            program = function()
                local prompt = 'Enter the path to the executable: '
                return vim.fn.input(prompt, vim.fn.getcwd(), "file")
            end,
            cwd = "${workspaceFolder}",
            stopOnEntry = true,
        },
    },

Debug adapter version

Latest

Steps to Reproduce

  1. Start ./codelldb --port 13000
  2. Open project
  3. Open main.c
  4. Put breakpoint
  5. Start dap.continue
  6. Debugger opens
  7. Error in console

Expected Result

No error should be observed.

Actual Result

image

@mfussenegger Also I am trying to make it work with the auto codelldb start but codelldb keeps throwing 1 as error code. Am i wrong, or is this config not correct ?

The spawn command does not provide any port. If i try to start codelldb from command line without port, it exits with the command that either --port or --connect are required.
image
Also when i start codelldb i am not seeing any logs in the console i.e no Listening on port message (but codelldb is running, mangaed to debug from vscode with that instance on 13000)

        adapter = function(callback, config)
            local stdout = vim.loop.new_pipe(false)
            local stderr = vim.loop.new_pipe(false)

            local handle, pid_or_err
            local opts = {
                stdio = { nil, stdout, stderr },
                args = { "--port", "98345" },
                detached = true,
            }

            local process = debugger.path .. "extension/adapter/codelldb"
            handle, pid_or_err = vim.loop.spawn(process, opts, function(code)
                stdout:close()
                stderr:close()
                handle:close()
                if code ~= 0 then
                    print("codelldb exited with code", code)
                end
            end)

            assert(handle, "Error running codelldb: " .. tostring(pid_or_err))
            stdout:read_start(function(err, chunk)
                assert(not err, err)
                if chunk then
                    local port = chunk:match('Listening on port (%d+)')
                    if port then
                        vim.schedule(function()
                            callback({
                                type = 'server',
                                host = '127.0.0.1',
                                port = port
                            })
                        end)
                    else
                        vim.schedule(function()
                            require("dap.repl").append(chunk)
                        end)
                    end
                end
            end)
            stderr:read_start(function(err, chunk)
                assert(not err, err)
                if chunk then
                    vim.schedule(function()
                        require("dap.repl").append(chunk)
                    end)
                end
            end)
        end,

I can't reproduce the error. Can you show the logs?

(Also, configurations is a list and don't have a name/key, your provided configuration wouldn't even work?)

I doubt you had time to try and reproduce it, but anyhow. For the first error there are no logs since session dap fails it does not even start the server - if you change stopOnEntry to false then it triggers the breakpoint, but with it being true it fails with this error above in dap. For the second point with codelldb, it just returns 1 since no port is provided, therefore i assume the config provided in the readme is wrong.

I doubt you had time to try and reproduce it,

No reason to make accusations like that.

This is how I installed it:

---
- name: Ensure codelldb folder exists
  file:
    path: ~/apps/codelldb
    state: directory

- name: Download codelldb
  unarchive:
    src: https://github.com/vadimcn/vscode-lldb/releases/download/v1.7.0/codelldb-x86_64-linux.vsix
    dest: ~/apps/codelldb
    remote_src: true

This is my configuration:

function M.codelldb()
  local dap = require('dap')
  dap.adapters.codelldb = {
    type = 'server',
    host = '127.0.0.1',
    port = 13000
  }
  dap.configurations.c = {
    {
      type = "codelldb",
      request = "launch",
      name = "Default launch (codelldb)",
      program = function()
        return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
      end,
      cwd = "${workspaceFolder}",
    },
  }
end

This was my test file:

#include <stdio.h>

int main() {
    int x = 10;
    int y = 20;
    printf("foobar\n");
    return 0;
}

This is how I started the debug adapter:

> ~/apps/codelldb/extension/adapter/codelldb --port 13000

For the first error there are no logs since session dap fails it does not even start the server

Your steps to reproduce show a flow where at least an error appears. If that is the case the session started and there have to be logs.

Yes I only looked at the problem in your initial issue description and didn't look at the second comment, because I like to do things one at a time and mixing multiple issues within one gets confusing quickly.

As for your second issue, codelldb dropped the ability to have it bind to a random port in 1.7.0. Someone else figured that out as well and updated the wiki just a couple days ago: https://github.com/mfussenegger/nvim-dap/wiki/C-C---Rust-(via--codelldb)/_compare/78e9f326eb83994e9af5ca43f8d7f42bfa055dac...414245e4dcb4b3cf4a6043ade007b3647bb3eea1

I also have the first issue by using lldb-vscode, did it fixed?