/weevil-debugger-plugin

Primary LanguageKotlinApache License 2.0Apache-2.0

Weevil Debugger plugin

Weevil Debugger is an extension to existing Intellij Java Debugger providing special features:

  • Evaluate future code
  • Object Diff
  • Debugger Shell with evaluation history and value inspection
  • Automatic closing files which aren't reachable from stack frames during Debug
  • Search for Debugger Variables
  • Recursion breakpoint
  • Smart breakpoint setup according to current value
  • Show source code path of loaded class

And features dedicated for evaluating future code:

  • Show method return values
  • Highlighting boolean operators
  • Highlighting selected expression
  • Variable change history

You can install this plugin from JetBrains marketplace.

Requirements

For Search and Evaluate future code features, it is required to have a running JVM with at least Java 8 version.

Warning

If your code is stateful, using Evaluate future code feature may cause unexpected program behavior (i.e. closing streams, sessions etc.).

Features

Debugger Shell

To open Debugger Shell just right-click in the editor after breakpoint hits.

img.png

After that, you should see a new Debug tab: Weevil Debugger Shell in which you can write and evaluate expressions.

img.png

Shell provides several actions such as:

  • Execute: executes selected expression or whole code in shell editor,
  • Inspect: inspects selected expression,
  • Refresh: refreshes the shell (you may need to click this if shell loses debug context),
  • Clear: clears the shell editor
  • Clear history: clears evaluation history

Troubleshooting Debugger Shell

Use Refresh action when Active label turns into Deprecated. Also, always check if the file path and line position label is the same as current breakpoint/step position.

img.png

Automatic closing debugged files

Files which were opened by breakpoint hit, step over, step into and step over action will be automatically closed. This will happen only when a file is not reachable by any JVM stack frame. Also, when you will stop Debug session, a prompt will show files which can be selected/unselected for closing. This feature can be disabled in Weevil Debugger Settings (Settings | Tools). Disabling or enabling will be reflected in the next debug session.

Search Variables

You can search debugger variables in two modes: Expression and Code fragment. It is similar to the existing Intellij Debugger Evaluator.

To start searching right-click on desired variable in Variables view and click on Search:

img.png

You can also start searching by clicking on inlay variable in the current editor:

img.png

If you need to search for simple values such as: integers, strings etc. use Expression mode, otherwise use Code fragment mode. To select proper mode click on Expand button.

Expression search

img.png

To search for desired value just write it in the input and hit Search button.

img.png

Search result (tree path) will be expanded and highlighted. Be aware that by default search depth is limited to 5 levels of object graph hierarchy. This is required because some JVM objects can hold cyclic references and searching process could take eternity. Search depth can be changed in Weevil Debugger Settings.

Searching process can also timeout. By default, it will timeout after 5 seconds. This value can be also changed in the plugin settings.

Code Fragment search

In this mode we can do a more complex search. For example, we can check if a particular getter property matches our expression. In Code Fragment mode you must operate on the $it variable and treat it as any object in the searched hierarchy. Type of $it is java.lang.Object (or Any in Kotlin) so remember about type checking.

In the following example we can see a Code Fragment that will find all employees whose names are starting with J.

img.png

Searching process is done in single thread. So if you are searching huge collections it will probably timeout and your desired value may not be found.

Evaluate Future Code

You can evaluate future code from current suspension point. Evaluated code is limited by number of lines (by default 10) and can be changed in Weevil Debugger Settings. After code evaluation you will see values in Future values view and inlay values at each end of line in the current editor.

img.png

You can search evaluated values and also inspect their history. Each history entry will have proper index.

img.png

Boolean expressions can be highlighted in editor. For true value highlighted color will be green, for false value red. You can also view method return values and references.

Limitations

  • At this moment only values for actual thread are showing.

  • Future code evaluation should be invoked only on stateless code.

Smart Breakpoints Setup

You can immediately set conditional breakpoint by clicking on the variable in Variables View (or add a shortcut in Keymap | Plugins | Weevil Debugger):

img.png

For JVM primitive types == operator will be used. For String type equals method.

img.png

For any other type no operator will be used (only the variable name will be added in the Condition input).

Recursion Breakpoint

Intellij already provides functionality to add recursion breakpoint. The problem is that it can be set for 1 pass/iteration. Weevil Debugger provides possibility to use ranges and multiple passes (just like in printing pages).

By default, this feature is disabled, because it can be annoying to do a second click to add a regular Java breakpoint.

To add it, just click on desired line.

img.png

After clicking, provide information at which iterations breakpoint should suspend program execution.

img.png

Keymap

You can add shortcuts to Weevil Debugger actions in Keymap | Plugins | Weevil Debugger.

img.png

Settings

Weevil Debugger Settings can be accessed in Settings | Tools.

  • Max search depth (default 5) - depth of search in object hierarchy,
  • Search timeout (in seconds, default 5) - timeout of searching process,
  • History limit (default 10) - length of history for particular value/expression evaluated in future mode,
  • Future evaluation limit (number of lines, default 10) - number of code lines which will be evaluated in future mode,
  • Show code source path (by default NOT checked) - if checked, code source path will be visible next to class name where program suspended,
  • Allow recursion breakpoint (by default NOT checked) - if checked, can put breakpoint at desired line,
  • Show method return values (by default NOT checked) - if checked, method return values will be visible during future evaluation mode.
  • Auto close unreachable files during debug (by default checked) - if checked, files which were opened during breakpoint hit, step into, step out and step over will be closed,
  • Show prompt to close unreachable files during debug (by default checked) - if checked, prompt will be opened to select files which can be closed.

img.png