vimで breakpoint を設置してステップ実行できるようなデバッガを調べた。

vim 上のデバッガ

lldb.nvim

vim-vebugger

なんか動きそうなのだが、 vimproc を使っていたので動かせなかった kaoriya 版の Vim を使うなどしてみたがよくわからず。

pyclewn

gdb と pdb のvimフロントエンド?

pubd

pythonのpdb.

vim-breakpts

vim スクリプト用?

vimspector

VSCodeの DebugAdapterProtocol を使うものらしい。

unknown: blockquote => {"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"While Language Server Protocol is well known, the Debug Adapter Protocol is less well known, but achieves a similar goal: language agnostic API abstracting debuggers from clients.","position":{"start":{"line":40,"column":3,"offset":557},"end":{"line":40,"column":182,"offset":736}}}],"position":{"start":{"line":40,"column":3,"offset":557},"end":{"line":40,"column":182,"offset":736}}}],"position":{"start":{"line":40,"column":1,"offset":555},"end":{"line":40,"column":182,"offset":736}}}

動かし方よくわからず。

DebugAdapterProtocol

読む。

unknown: blockquote => {"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"The \"deep understanding of a language\" is surfaced by the Language Server Protocol (LSP) and the \"debugging support\" by the Debug Adapter Protocol (DAP).","position":{"start":{"line":51,"column":3,"offset":961},"end":{"line":51,"column":156,"offset":1114}}}],"position":{"start":{"line":51,"column":3,"offset":961},"end":{"line":51,"column":156,"offset":1114}}}],"position":{"start":{"line":51,"column":1,"offset":959},"end":{"line":51,"column":156,"offset":1114}}}
editor <=> adapter <=> gdb
              ||
              ++=====> pdb

adapterでラップして同じに見えるようにする。

adapterの起動設定は、 .vscode/launch.json にというわけか。

unknown: blockquote => {"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"The Debug Adapter Protocol is not tied to VS Code and can be used as the foundation for a generic debugger UI in other development tools.","position":{"start":{"line":63,"column":3,"offset":1272},"end":{"line":63,"column":140,"offset":1409}}}],"position":{"start":{"line":63,"column":3,"offset":1272},"end":{"line":63,"column":140,"offset":1409}}}],"position":{"start":{"line":63,"column":1,"offset":1270},"end":{"line":63,"column":140,"offset":1409}}}

新サイトで仕様を公開していくで、って書いてあるね。

読む。

unknown: blockquote => {"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"single session mode: in this mode, the development tool starts a debug adapter as a standalone process and communicates with it through stdin and stdout.","position":{"start":{"line":74,"column":3,"offset":1633},"end":{"line":74,"column":156,"offset":1786}}}],"position":{"start":{"line":74,"column":3,"offset":1633},"end":{"line":74,"column":156,"offset":1786}}}],"position":{"start":{"line":74,"column":1,"offset":1631},"end":{"line":74,"column":156,"offset":1786}}}
unknown: blockquote => {"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"multi session mode: in this mode, the development tool does not start the debug adapter but assumes that it is already running and that it listens on a specific port for connections attempts.","position":{"start":{"line":76,"column":3,"offset":1790},"end":{"line":76,"column":194,"offset":1981}}}],"position":{"start":{"line":76,"column":3,"offset":1790},"end":{"line":76,"column":194,"offset":1981}}}],"position":{"start":{"line":76,"column":1,"offset":1788},"end":{"line":76,"column":194,"offset":1981}}}

DAPの仕様

DAPの実装

ネイティブコンパイルするタイプは言語ごとではなく、ネイティブコンパイルの様式ごとに違うものになる。例えば、 vc , gcc , llvm のように。

となるとVMタイプのものは、 .Net, Mono, java といった分類になるのだろうか。 C#, F# が両方デバッグできたりしそうではある。

インタープリター型はそれぞれの言語ごとになる。

あとは、リモートデバッグの事情を調べる。

native debug

c++やd, rustなんかのnativeコードを出力するものをまとめて面倒見れるという理解であったいるのかな。ビルド形式とデバッグビルドに付加される情報のフォーマットに対応してデバッガを選択する必要があると。

LLVM

.Net

unknown: blockquote => {"type":"blockquote","children":[{"type":"paragraph","children":[{"type":"text","value":"Mono debugging is not supported.","position":{"start":{"line":107,"column":3,"offset":2599},"end":{"line":107,"column":35,"offset":2631}}}],"position":{"start":{"line":107,"column":3,"offset":2599},"end":{"line":107,"column":35,"offset":2631}}}],"position":{"start":{"line":107,"column":1,"offset":2597},"end":{"line":107,"column":35,"offset":2631}}}

ILは互換性があるにしても、VMのデバッグインタフェースは互換性が無いということなのかな。

Mono

Unity

UnityEditorにアタッチできるらしい。 Unity版のMonoにアタッチできるということかしら。

lua / ravi

こんなのあるのか・・・

powershell

python

vimspectorの実装

読む。

.\install_gadget.py

を実行することで、 VSCodeextensiondownload する。 extension に、 DAP が含まれているのでこれを使う。

autoload/vimspector.vim

function! vimspector#Launch() abort
  py3 _vimspector_session.Start()
endfunction

python3/vimspector/debug_session.py

class DebugSession:
  def Start():
    pass

vim.bindeval を使っているので、 vim8 専用。 nvim では回避する必要がある。

.vimspector.json

{
    "adapters": {
    },
    "configurations": {
    }
}

configurations からデバッグセッションの起動方法を取得して、 デバッグアダプターを vimjobchannel 経由で起動する。 configurations.vscode/launch.json に相当するようだ。 adapters は、インストールされている DebugAdapter のリスト。

call vimspector#Launch() simple_python - launch /Users/ousttrue と入力することでjobが、アダプター開始するところまでできた。 しかし、アダプターがすぐに死んでいる様子。

アダプターを手動起動してみる。

node .\.vscode\extensions\ms-python.python-2019.4.11987\out\client\debugger\debugAdapter\main.js

.vimspector.json に書いてあるのとバージョンが違う。 file not found か。

path をなおしたら動いた😃

-          "$HOME/.vscode/extensions/ms-python.python-2018.4.0/out/client/debugger/Main.js"
+          "$HOME/.vscode/extensions/ms-python.python-2019.4.11987/out/client/debugger/debugAdapter/Main.js"

neovimrplugin での構成を考えてみようか。

python3 で Adapter を起動してみる

AdapterAdapter というか AdapterBridge という感じになりそうだけど、 vim で込み入った実装をするのは手に余るので、可能な限り python で事を進めよう。 pythonでprotocl実験。

https://github.com/ousttrue/daplauncher

launchRequestの後で固まると思ったら、サイトに記述されていないパラメーターがあった。 console どこに書いてあるのか・・・

https://github.com/Microsoft/vscode-debugadapter-node/blob/master/debugProtocol.json

https://github.com/Microsoft/vscode-python/issues/3762

わかった。

https://github.com/Microsoft/vscode-go/issues/219

vscodeの .vscode/launch.json の起動設定を launch の引数に合体するのだ。

https://code.visualstudio.com/Docs/editor/debugging#_launchjson-attributes

書いとけよー。