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.
For Search
and Evaluate future code
features, it is required to have a running JVM
with at least Java 8 version.
If your code is stateful, using Evaluate future code
feature may cause unexpected program behavior (i.e. closing streams, sessions etc.).
To open Debugger Shell just right-click in the editor after breakpoint hits.
After that, you should see a new Debug tab: Weevil Debugger Shell
in which you can write and evaluate
expressions.
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 editorClear history
: clears evaluation history
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.
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.
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
:
You can also start searching by clicking on inlay variable in the current editor:
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.
To search for desired value just write it in the input and hit Search
button.
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.
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
.
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.
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.
You can search evaluated values and also inspect their history. Each history entry will have proper index.
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.
-
At this moment only values for actual thread are showing.
-
Future code evaluation should be invoked only on stateless code.
You can immediately set conditional breakpoint by clicking on the variable in Variables
View
(or add a shortcut in Keymap | Plugins | Weevil Debugger
):
For JVM primitive types ==
operator will be used.
For String
type equals
method.
For any other type no operator will be used (only the variable name will be added in the Condition
input).
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.
After clicking, provide information at which iterations breakpoint should suspend program execution.
You can add shortcuts to Weevil Debugger actions in Keymap | Plugins | Weevil Debugger
.
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.