简体   繁体   English

在eclipse中调试时实时更改变量?

[英]Changing variables in realtime when debugging in eclipse?

Using Eclipse, when debugging is it possible to change the value of variables during runtime of a project for testing purposes. 使用Eclipse时,在调试时可以在项目运行期间更改变量值以进行测试。

For example, say I have a method that returns the number 5 but for testing purposes i want to output 10 instead. 例如,假设我有一个返回数字5的方法,但出于测试目的,我想输出10。 This isn't the problem I'm facing its a little more complex but its just to get my idea across. 这不是我面临的问题,它有点复杂,但它只是为了让我的想法得以实现。

You should be able to set a break-point, go into debug mode, open the variables views and here change the content of the variables. 您应该能够设置断点,进入调试模式,打开变量视图,这里更改变量的内容。

在此输入图像描述

You can access variables through the Variables view . 您可以通过“ 变量”视图访问变量。 There you can right click on any variable and select " Change value ... ". 在那里,您可以右键单击任何变量,然后选择“ 更改值... ”。


Resources : 资源:

... and you can do much, much more:-) Just to give you and idea. ......你可以做更多,更多:-)只是为了给你和想法。
You may change the code during debug which is hot swapped and is effectively changed (recompiled) in given debug session. 您可以在调试期间更改代码,该代码是热交换的,并且在给定的调试会话中有效地更改(重新编译)。 You may run given method run (eg after catching breakpoint) few times without rerunning debug -> use drop to frame feature on method stack. 你可以运行给定的方法运行(例如在捕获断点之后)几次而不重新运行调试 - >在方法堆栈上使用drop to frame功能。

After you have changed the code you have to save it (cntrl-S) to make it effective. 更改代码后,必须保存它(cntrl-S)才能使其生效。 You will see your running application respond to the code-change after the cntrl-S 在cntrl-S之后,您将看到正在运行的应用程序响应代码更改

I hope this works for you. 我希望这适合你。 it took me some time to figure this out. 我花了一些时间才弄明白这一点。

Run your application in debug mode then go to variables window. 在调试模式下运行应用程序,然后转到变量窗口。 select the parameter then change values according to your requirements. 选择参数,然后根据您的要求更改值。 then save (ctrl+s). 然后保存(ctrl + s)。 and go ahead with your changes. 并继续你的改变。 Hope this will help. 希望这会有所帮助。

If variables window is missing. 如果缺少变量窗口。 then goto eclipse window->show views->variables 然后转到eclipse window-> show views-> variables

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

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