Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C CPP Rust (via codelldb)

Chinmay Dalal edited this pageJan 1, 2023 ·1 revision

C/C++/Rust (via codelldb)

Configuration examples are in Lua. See:help lua-commands if your Neovim setup so far uses ainit.vim file.

Installation

Installcodelldb:

  • Download theVS Code extension.
  • Unpack it..vsix is a zip file and you can useunzip to extract the contents.

Adapter definition

codelldb uses TCP for the DAP communication - that requires using theserver type for the adapter definition. See:help dap-adapter.

Start codelldb manually in a terminal

Up to including version 1.6.10 you could launchcodelldb and it printed out a port it was listening to:

$ codelldbListening on port 13123

Starting with version 1.7.0 it is necessary to specify the port:

$ codelldb --port 13000

To have nvim-dap connect to it, you can define an adapter like this:

localdap=require('dap')dap.adapters.codelldb= {type='server',host='127.0.0.1',port=13000-- 💀 Use the port printed out or specified with `--port`}

With this adapter definition you'll have to launchcodelldb manually in aterminal first whenever you want to debug your application.

Start codelldb automatically

If you want nvim-dap to automatically spawn the debug adapter beforeconnecting, you can use the following for version 1.7.0 and later:

dap.adapters.codelldb= {type='server',port="${port}",executable= {-- CHANGE THIS to your path!command='/absolute/path/to/codelldb/extension/adapter/codelldb',args= {"--port","${port}"},-- On windows you may have to uncomment this:-- detached = false,  }}
For version 1.6.10 and earlier
localdap=require('dap')dap.adapters.codelldb=function(on_adapter)localstdout=vim.loop.new_pipe(false)localstderr=vim.loop.new_pipe(false)-- CHANGE THIS!localcmd='/absolute/path/to/codelldb/extension/adapter/codelldb'localhandle,pid_or_errlocalopts= {stdio= {nil,stdout,stderr},detached=true,  }handle,pid_or_err=vim.loop.spawn(cmd,opts,function(code)stdout:close()stderr:close()handle:close()ifcode~=0thenprint("codelldb exited with code",code)endend)assert(handle,"Error running codelldb:"..tostring(pid_or_err))stdout:read_start(function(err,chunk)assert(noterr,err)ifchunkthenlocalport=chunk:match('Listening on port (%d+)')ifportthenvim.schedule(function()on_adapter({type='server',host='127.0.0.1',port=port          })end)elsevim.schedule(function()require("dap.repl").append(chunk)end)endendend)stderr:read_start(function(err,chunk)assert(noterr,err)ifchunkthenvim.schedule(function()require("dap.repl").append(chunk)end)endend)end

  • Rust-Tools only If you are using this adapter for debugging Rust and are using therust-tools extension, there is a helper function defined for setting upCodeLLDB.This helper function works the same way as the function defined in the point above.Set it up as definedhere.

Have a look at thisissue for more information onCodeLLDB definition.

Configuration

Thecodelldb manual contains a full reference for all options supported by the debug adapter.

A common configuration example:

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

If you want to use this debug adapter for other languages, you can re-use the configurations:

dap.configurations.c=dap.configurations.cppdap.configurations.rust=dap.configurations.cpp

The executables that you want to debug need to be compiled with debug symbols.

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp