在Eclipse中进行调试:无断点的可变快照 [英] Debugging in Eclipse: Variable Snapshot Without Breakpoint

查看:74
本文介绍了在Eclipse中进行调试:无断点的可变快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Eclipse中调试Java程序。我想看一个特定的变量。但是,由于我的程序使用GUI,因此创建断点会导致窗口冻结。当例如尝试右键单击某个项目并导航上下文菜单。

I am debugging a Java program in Eclipse. I would like to watch a specific variable. However, since my program uses a GUI, creating a breakpoint causes the window to freeze. This is particularly annoying when e.g. trying to right click on an item and navigate a context menu.

我实际上并不想停止程序,我只想观看特定的变量并记录其变量每次到达特定行时的值。目前,我正在使用print语句执行此操作,但是我想知道是否存在使用调试视图执行此操作的方法。

I don't actually want to stop the program, I just want to watch a specific variable and log its value every time a certain line is reached. At the moment, I am doing that with print statements, but I was wondering whether there was a way to do this using the debug view.

(注意:我不想将其写入日志文件。这不是我需要长期看的变量。目前,我只是打印找出它所需要的值,然后删除print语句。最好有这样的东西,我可以将其保留在调试视图中,而不会使print / log语句使我的代码混乱。

(Note: I don't want to write this to a log file. This is not a variable I need to look at long term. At the moment I just print it out, look at the values it takes on, and then delete the print statement. It would be nice to have something like this which I can keep in the debug view without having print / log statements cluttering my code).

推荐答案

您可以添加返回false的条件断点。条件中的代码将被评估,然后返回false以向调试器指示您不想停止执行。

You can add a conditional breakpoint that returns false. The code in the condition will be evaluated, and then you return false to indicate to the debugger that you do not want to stop execution.

右键单击断点属性,
选中有条件的
在文本字段中,输入要运行的代码(例如,打印x) 。确保条件中的最后一个语句为 return false

Right click on breakpoint properties, Check "Conditional" In the text field, enter the code you want to run (e.g. print x). Make sure the last statement in the condition is "return false"

这是我的代码:

public static void main(String[] args) {
        String x  = " Some value"; 
        String y  = "a value"; //breakpoint here
        System.out.println("Hello World!");
    }

说我想在声明x之后立即打印x的值。
在代码中指示的位置设置断点
添加条件:

Say I want to print the value of x just after it is declared. Set a breakpoint where indicated in the code, Add a condition:

System.out.println("Value of x: " + x);
return false;

输出:

Value of x: Some Value
Hello World!

这篇关于在Eclipse中进行调试:无断点的可变快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆