How skip line in Intellij idea debug?

旧街凉风 提交于 2019-12-29 04:29:07

问题


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 "int a = b+2;" and go immidiatly to "System.out.prinln(a);"?

P.S. I use Intellij Idea 12.


回答1:


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.

Note that

  1. Suspend isn't checked
  2. Log evaluated expression is used to alter a variable when the break point is hit



回答2:


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




回答3:


You can't just skip 'line execution' when debugging. You can press F8 to step over.




回答4:


It is not possible to skip the EXECUTION of the lines in IntelliJ and even in Eclipse. Only thing you can do is you can do step over (F8)-which will trace line by line without going inside any function.

One more thing is Step out(Shift+F8)- which will go to next debug point directly by executing in between lines in that single step.




回答5:


As stated here by ntotomanov , you can use HotSwap for it. but just adding that i use remote debug to debug my Docker based apps , so if i want this kind of functionality i just comment out the code , and go to Build -> Recompile class or Rebuild Project . then Intellij issues Build & Attempting to HotSwap the code ! in case you did small thing like comment out the code it most of the times always succeeds. happy debugging.



来源:https://stackoverflow.com/questions/17462457/how-skip-line-in-intellij-idea-debug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!