How skip line in Intellij idea debug?

前端 未结 6 1450
借酒劲吻你
借酒劲吻你 2020-12-15 03:30

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;
    Sy         


        
相关标签:
6条回答
  • 2020-12-15 03:53

    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
    0 讨论(0)
  • 2020-12-15 04:00

    Intellij recently published a blog post about a plugin called Jump to Line that can accomplish this, even though Intellij itself doesn't have this functionality. It really is surprising that Intellij still doesn't have this functionality, when Visual Studio has had it for so many years!

    https://blog.jetbrains.com/idea/2020/08/jump-to-any-line-while-debugging/

    0 讨论(0)
  • 2020-12-15 04:02

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

    0 讨论(0)
  • 2020-12-15 04:03

    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.

    0 讨论(0)
  • 2020-12-15 04:05

    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.

    0 讨论(0)
  • 2020-12-15 04:07

    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

    0 讨论(0)
提交回复
热议问题