Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How skip line in Intellij idea debug?

Suppose I have java code like this (only as Example):

public void someMethod(){     int a = 3;     int b = 2; // <-- stay debug here     a = b + 2;     System.out.prinln(a); } 

It is possible to skip execution of line a = b + 2; and go immidiatly to System.out.prinln(a);?

P.S. I use Intellij Idea 12.

like image 370
Cherry Avatar asked Jul 04 '13 05:07

Cherry


People also ask

How do I skip a Debug line in Intellij?

If you press and hold the Ctrl / ⌘ button while dragging the arrow, the IDE will highlight all the lines in green. When you drop the arrow, you won't jump to the line of code. Instead, the IDE will act as if you have used the Run to Cursor (⌥F9) action.

How do I jump to the next line in Intellij?

Press ⌥⇧↑ (macOS), or Alt+Shift+Up Arrow (Windows/Linux), to move a line up. To move a line down use ⌥⇧↓ (macOS), or Alt+Shift+Down Arrow (Windows/Linux).

How do you go to the next line in Intellij Debug on a Mac?

Step Over (F8) lets you execute a line of code and move on to the next line. As you step through the code, you'll see the value of the variables next to the code in the editor window.

How do I skip a line while debugging in Visual Studio?

You can also click on the line you want to skip to and hit Ctrl+F10 (Run to Cursor). It will jump directly to that line.


2 Answers

It's not possible with the debugger to not execute parts of the code.

It is however possible to execute extra code and change values on variables so if you need to exclude one row from execution during debug you will have to alter your code to prepare for that kind of debugging.

public void someMethod() {     int a = 3;     int b = 2;     boolean shouldRun = true;     if (shouldRun) {         a = b + 2;     }     System.out.prinln(a); } 

You would then set a break point that changes the value of shouldRun without stopping execution. It can be done like this.

enter image description here

Note that

  1. Suspend isn't checked
  2. Log evaluated expression is used to alter a variable when the break point is hit
like image 122
Andreas Wederbrand Avatar answered Oct 04 '22 10:10

Andreas Wederbrand


It is possible to skip lines only if you use hotswapping, or put in other words, code reloading tool - add code changes/new code at runtime. Hotswapping is the functions of replacing components without shutting down the system. Hotswapping can also refer to the ability to alter the running code of a program without needing to interrupt its execution.

There are various hotswapping tools like: JRebel (https://zeroturnaround.com/software/jrebel/) or HotSwapAgent (http://www.hotswapagent.org/)

You avoid having to rebuild the entire application to reload code changes, this is a huge time savings. Instead of running your full build process, simply use the compiler built into your IDE and the hotSwap agent/tool will reload the code into the JVM.

In this case, it would not be actually skipping, but you can just comment/change the lines and reload it. This tools are quite awesome!!!! It greatly speeds up the development/debugging process.

like image 37
ntotomanov Avatar answered Oct 04 '22 09:10

ntotomanov