Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debug an evaluate expression on intellij

Using evaluate expression/code fragment:

https://www.jetbrains.com/idea/help/evaluating-expressions.html

Is it possible to debug evaluated expression/code fragment on intellij?.

On eclipse if you launch a code evaluation on display window and that code has any breakpoint inside, eclipse debugger stops on that breakpoint. If you try again eclipse says it can execute inspections on nested debug session.

Intellij seems to launch expression in a different session.

My workflow on this is to stop on "whatever line" of code and add fragment I want to evaluate for a Q&D debug. Many times this leads to a debug restart.

like image 361
albfan Avatar asked Sep 15 '15 11:09

albfan


People also ask

How do I debug a method in IntelliJ?

Run the program in debug mode Click the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.

Can you explain the evaluate expression action with debugger?

Evaluate Expression to the rescue. Debugging means poking around, usually at a point in the execution. You set a breakpoint, fire up the debugger, and start pokin'. Sometimes "poking" means "typing in expressions and seeing the result values." This is where Evaluate Expression helps.

How do I debug a script in IntelliJ?

Start debugging Open the HTML file that references the JavaScript to debug or select the HTML file in the Project tool window. From the context menu of the editor or the selection, choose Debug <HTML_file_name>. IntelliJ IDEA generates a debug configuration and starts a debugging session through it.

What is the shortcut for evaluating the value of an expression?

You can also invoke the value tooltip on a variable, expression, or selection with the Quick Evaluate Expression command ( Ctrl+Alt+F8 or Run | Quick Evaluate Expression or Alt -click ).


2 Answers

Unfortunately it's not possible in Intellij 14 and stated in the official link you provided:

If a method invoked within the Expression Evaluation has a breakpoint inside its body, this breakpoint will be ignored.

To eliminate the problem you mentioned with frequent restarting of a debug session I use the following work-around with the drop-frame debug feature:

  1. Step in to a method and before return use the drop-frame functionality to fall back to a previous stack frame. See the drop-frame icon's location on the screenshot below: enter image description here
  2. Now it's possible to rerun this method with different parameters without restarting the debug session (parameters can be set using Evaluate Expression dialog).
like image 52
Andrew Terekhine Avatar answered Sep 19 '22 09:09

Andrew Terekhine


The feature is not available in IntelliJ IDEA 2019.2

The workaround I use is to update the code as follows,

                    Boolean shouldExecute = false;                     if(shouldExecute){                         //method call                     } 

During the debug session, I will change shouldExecute flag to true. This way I can debug the method call when needed.

Of coarse this is just a workaround, I need to remove this flag later.

like image 37
Karthik P Avatar answered Sep 23 '22 09:09

Karthik P