概要
2018/09/10 VSCodeによるNimのデバッグを追加しました。VSCodeによるステップ実行ができます。
nimでのデバッグ・ステップ実行の手段は今のところ2種類あるようです。
- デバッグオプションを指定して実行
- KDevelopでnimプラグインを利用してデバッグ(おすすめ!!nim-0.14.0でも可能です)
デバッグオプションで実行
以下のようなコマンドラインで実行すると、起動時にプロンプトモードとなります。
Embedded Nim Debugger
注意:Emedded Nim Debuggerは、もうメンテされていないようで、次のバージョンで使えるかどうかはなんとも言えないようです。
# 実行例
nim c --run --debugger:on ref_basic.nim
実行結果
$nim c --run --debugger:on ref_basic.nim
Hint: system [Processing]
Hint: ref_basic [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
ref_basic.nim(14, 7) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
ref_basic.nim(16, 5) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
ref_basic.nim(20, 1) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
ref_basic.nim(22, 8) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
ref_basic.nim(24, 5) Hint: 'i' is declared but not used [XDeclaredButNotUsed]
Hint: [Link]
Hint: operation successful (12979 lines compiled; 0.306 sec total; 20.209MB; Debug Build) [SuccessX]
*** endb| ref_basic.nim(15) ref_basic ***
*** endb| >> (<-デバッガが起動して、コマンド待ち状態です)
これ以降は、コマンドにてブレークポイントを設定したり、ステップイン・ステップオーバー、ステップアウトなどを実行していきます。
| コマンド | 内容 |
|---|---|
| h | ヘルプを表示 |
| q | デバッガを終了 |
| s | ステップイン |
| n | ステップオーバー |
| f | 現在の行の実行をスキップ |
| c | 実行を継続 |
| r | ブレークポイントか終了まで実行(cと同じかな?) |
| b | ブレークポイントを設定 例) test.nim の10行目にブレークポイントを設定 b 10 test |
| toggle | ブレークポイントのON/OFFを設定する 例) toggle 10 test |
| i | ブレークポイントをすべて無視する |
| breakpoints | ブレークポイント一覧を表示 |
| l | ローカル変数の値を表示 |
| g | グローバル変数の値を表示 (うまく動きませんでした・・・) |
| e | 式の評価を行う (うまく動きませんでした・・・) |
| stackframe | コールスタックの表示 |
| bt | バックトレース(コールスタック)の表示(python風?) |
| w | 現在の行位置を表示します |
ソースコード内にも、プラグマを利用して、ブレークポイントやウォッチポイントを指定出来ます。
Kdevelopでのデバッグ
CentOS7のGnome環境でKDevelopを実行してみましたが、かなり快適です。
当面は、KDevelopでnimの勉強が捗りそうです。
追記: 2016/6/10
nim-0.14.0での動作も確認できました。