LoginSignup
0
0

デバッガーのStep Into, Step Over, Step Outの使い分け

Last updated at Posted at 2024-02-04

経緯

普段なんとなくデバッガーを使っていた

Step IntoやStep Over, Step Outの操作の違いについて、使い分けを特に意識せず、
なんとなくで感覚的に使っていた。

ふと気になったので、この機会に調べてみて、
自分なりに使い分けを考えてみた。

公式ドキュメント

公式ドキュメントを調べてみた。

Debug actions

Once a debug session starts, the Debug toolbar will appear on the top of the editor.

Debug toolbar

Action Explanation
Continue / PauseF5 Continue: Resume normal program/script execution (up to the next >breakpoint).Pause: Inspect code executing at the current line and debug line-by-line.
Step OverF10 Execute the next method as a single command without inspecting or following >its component steps.
Step IntoF11 Enter the next method to follow its execution line-by-line.
Step OutShift+F11 When inside a method or subroutine, return to the earlier execution >context by completing remaining lines of the current method as though it were a single >command.
RestartCtrl+Shift+F5 Terminate the current program execution and start debugging again >using the current run configuration.
StopShift+F5 Terminate the current program execution.

デバッガーのstep in, step over, step out の使い分け

以下のように考えてみた。
目的意識がはっきりと持てた気がする。
とくに、Step Into連打して、よく迷子になっていたので、
スコープ内の粒度を意識して、Step Overを使用する用に意識付けると、
コンテキストが保たれるので迷子にならなさそう。

Step Into

1行1行処理を追いかけたい時に使用する。
特定の関数やメソッドなど、処理内容を詳細に理解する必要がある時に使う。

Step Over

現在のスコープ内で処理の流れを追いたい時に使用する。
スコープ内の粒度を保ち、大まかな流れを把握したい時に使用する。

Step Out

スコープ内で途中まで処理を追いかけて、途中で処理内容を把握できた時に使う。
Step Intoで関数やメソッド内部に入りデバッグするという場面において、
そのスコープ内で知りたい事を把握でき目的が達成された時、デバッグを切り上げるために使う。

2024/2/24 追記
デバッガ―のショートカットのキーマッピングから気づいたが、
Step IntoとStep Overは、F11とShift+F11に割付けられているので、
セットで使うというのは、当たり前の事だったかもしれない。
シュートカットのキーマッピングに着目すると、使い方を理解するヒントになるかもしれない。

参考

感想

ドキュメントを読んでいたら、
把握していなかった機能が結構あった。

  • Logpoints(処理を一時停止するかわりに、ログを出力するブレークポイント的なもの)
  • Data breakpoints(変数へのアクセスや変更に対するブレークポイント)
  • Conditional breakpoints(条件式に概要する場合に、一時停止されるブレークポイント)など

実は、VS Codeのデバッガーの機能のほとんどを知らなかった事が分かった。
ドキュメントを読んで見ると、新たな発見が多く面白かった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0