Eclipse:编辑源代码并继续调试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8426650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:25:19  来源:igfitidea点击:

Eclipse :Edit the source and continue debugging

eclipsedebugging

提问by Pawan

I am using Eclipse IDE (Helios Version) While debugging in Eclipse , is it possible to edit the source and continue debugging ??

我正在使用 Eclipse IDE(Helios 版本)在 Eclipse 中调试时,是否可以编辑源代码并继续调试??

For example i have this file While debugging when i tried to modify the a4 value during debugging its not reflecting ??

例如,当我在调试期间尝试修改 a4 值时,我有这个文件在调试时它没有反映??

public class Tes {

    public static void main(String args[]) {
        int a4 = 15;

        for (int i = 0; i < a4; i++) {
            System.out.println(i);
        }

    }
}

采纳答案by nowaq

Yes it is possible to edit the source and continue debugging in Eclipse! You'll find extensive information here: Debugging with the Eclipse Platform(scroll down to the section Hotswap Bug Fixing: On-the-fly code fixing).

是的,可以在 Eclipse 中编辑源代码并继续调试!您将在此处找到大量信息:使用 Eclipse 平台进行调试(向下滚动到Hotswap Bug Fixing: On-the-fly code fix部分)。

If you are running Java Virtual Machine (JVM) V1.4 or higher, Eclipse supports a feature called Hotswap Bug Fixing (not available in JVM V1.3 or lower). It allows the changing of source code during a debugger session, which is better than exiting the application, changing the code, recompiling, then starting another debugging session. To use this function, simply change the code in the editor and resume debugging.

如果您运行的是 Java 虚拟机 (JVM) V1.4 或更高版本,Eclipse 支持称为 Hotswap Bug Fixing 的功能(在 JVM V1.3 或更低版本中不可用)。它允许在调试器会话期间更改源代码,这比退出应用程序、更改代码、重新编译,然后启动另一个调试会话要好。要使用此功能,只需在编辑器中更改代码并继续调试即可。

There are some cases where the feature will not work. E.g. if you make changes to your mainmethod's a4variable, the JVM will not be able to remove all stack frames running old code from the call stack. The debugger data will be lost.

在某些情况下,该功能将不起作用。例如,如果您更改main方法的a4变量,JVM 将无法从调用堆栈中删除所有运行旧代码的堆栈帧。调试器数据将丢失。

To see the Hotswap Bug FixingJVM feature in action, just move the code from your mainmethod in the Testclass to some other class. Here's what I mean:

要查看运行中的Hotswap Bug FixingJVM 功能,只需将代码从类中的main方法移动Test到其他类。这就是我的意思:

Hotswap Bug Fixing in Action

热插拔错误修复在行动

Now you can modify the code on the fly while debugging in the MyObjectclass. Have fun!

现在,您可以在MyObject类中调试时动态修改代码。玩得开心!

EDIT:Just found a similar question at superuser.com: Debugging in Eclipse, how to run until a breakpoint

编辑:刚刚在 superuser.com 上发现了一个类似的问题:Debugging in Eclipse, how to run until a breakpoint

回答by Purnesh

If you happen to be running your application using a 1.3 JVM or higher versions, there's one final step with the debugger still running: -> change the problem line - in your case "a4 value" and then Save the file, then press the Resume button to get the application running again.

如果您碰巧使用 1.3 JVM 或更高版本运行应用程序,则调试器仍在运行的最后一步是:-> 更改问题行-在您的情况下为“a4 值”,然后保存文件,然后按恢复按钮使应用程序再次运行。

This Saving of that particular java file that you have edited during debugging, will make the session to continue debugging from start(Constructor) of the file with new values.

保存您在调试期间编辑的特定 java 文件,将使会话使用新值从文件的开始(构造函数)继续调试。

This editing and saving can be done n number of times, and once you save it, the debugging session will automatically resume from the start of that particular file.

这种编辑和保存可以进行 n 次,一旦保存,调试会话将自动从该特定文件的开头恢复。

回答by Fredrik

If you just want to change the value of a5during debugging its alot easier than changing the source. You can set a new value in the variables view you can see when in the debugging perspective in Eclipse.

如果您只想a5在调试期间更改 的值,那么它比更改源要容易得多。您可以在变量视图中设置一个新值,您可以在 Eclipse 的调试透视图中看到。

See the manual hereand here

请参阅此处此处的手册