简体   繁体   English

Intellij 想法调试中如何跳线?

[英]How skip line in Intellij idea debug?

Suppose I have java code like this (only as Example):假设我有这样的 Java 代码(仅作为示例):

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;"可以跳过“int a = b+2;”行的执行and go immidiatly to "System.out.prinln(a);"?并立即转到“System.out.prinln(a);”?

PS I use Intellij Idea 12. PS我使用Intellij Idea 12。

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.然后,您将设置一个断点,在不停止执行的情况下更改 shouldRun 的值。 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日志计算表达式用于在遇到断点时更改变量

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/ )有各种热插拔工具,例如:JRebel ( https://zeroturnaround.com/software/jrebel/ ) 或 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.无需运行完整的构建过程,只需使用 IDE 中内置的编译器,hotSwap 代理/工具会将代码重新加载到 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.它大大加快了开发/调试过程。

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. IntelliJ 最近发布了一篇关于一个名为Jump to Line的插件的博客文章,它可以实现这一点,即使 IntelliJ 本身没有这个功能。 It really is surprising that IntelliJ still doesn't have this functionality, when Visual Studio has had it for so many years!令人惊讶的是,IntelliJ 仍然没有这个功能,而 Visual Studio 已经拥有它这么多年了!

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

You can't just skip 'line execution' when debugging.调试时不能只是跳过“行执行”。 You can press F8 to step over.您可以按 F8 跳过。

As stated here by ntotomanov , you can use HotSwap for it.正如 ntotomanov 在此处所述,您可以使用 HotSwap。 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 .但只是补充说我使用远程调试来调试我的基于 Docker 的应用程序,所以如果我想要这种功能,我只需注释掉代码,然后转到 Build -> Recompile class 或 Rebuild Project 。 then Intellij issues Build & Attempting to HotSwap the code !然后 Intellij 发出 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.调试愉快。

It is not possible to skip the EXECUTION of the lines in IntelliJ and even in Eclipse.不可能跳过 IntelliJ 甚至 Eclipse 中行的 EXECUTION 。 Only thing you can do is you can do step over (F8)-which will trace line by line without going inside any function.你唯一能做的就是你可以做 step over (F8) - 这将逐行跟踪而不进入任何函数。

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.还有一件事是 Step out(Shift+F8) - 它将通过在单个步骤中的行之间执行直接进入下一个调试点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM