Java 如何使用 Eclipse 的显示视图进行调试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4499944/
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
How to use Eclipse's Display View for Debug?
提问by jzd
At the link below it explains that the "display view allows you to manipulate live code in a scrapbook type fashion (see Figure 8). To manipulate a variable, simply type the name of the variable in the Display view, and you'll be greeted with a familiar content assist."
在下面的链接中,它解释了“显示视图允许您以剪贴簿类型的方式操作实时代码(参见图 8)。要操作变量,只需在显示视图中键入变量的名称,您就会迎接熟悉的内容帮助。”
http://www.ibm.com/developerworks/library/os-ecbug/
http://www.ibm.com/developerworks/library/os-ecbug/
However, I am having trouble getting it to work. I have the view open but all the buttons are disabled. I have tried putting code in the view, selecting code in the view, selecting code in other views, while running and while not running debug, but the only button that is ever enabled on the view is "clear console".
但是,我无法让它正常工作。我打开了视图,但所有按钮都被禁用。我试过在视图中放置代码,在视图中选择代码,在其他视图中选择代码,同时运行和不运行调试,但视图上唯一启用的按钮是“清除控制台”。
Suggestions on what I am doing wrong?
关于我做错了什么的建议?
采纳答案by dimitrisli
You can view the Display
view as a place where you can inspect all sorts of variables and boolean expressions during runtime. While your debugger is frozen on a breakpoint start typing the name of an object variable for instance and you'll get autocomplete functionality as you start calling methods or fields to reach deeper class datastructures. Then when you select/mark the portion you need to inspect or everything, the buttons on the Display view will be clickable. You can always perform the Ctrl+Shift+I
shortcut on the selection to view what's the current runtime state of your selection i.e. variable, object, boolean exrepssion etc
您可以将Display
视图视为可以在运行时检查各种变量和布尔表达式的地方。例如,当您的调试器在断点处冻结时,开始键入对象变量的名称,当您开始调用方法或字段以访问更深的类数据结构时,您将获得自动完成功能。然后,当您选择/标记需要检查的部分或所有内容时,“显示”视图上的按钮将是可点击的。您始终可以在Ctrl+Shift+I
选择上执行快捷方式以查看选择的当前运行时状态,即变量、对象、布尔表达式等
回答by Joel
It will only work while running in debug, and you can only manipulate variables that are live in the context of the currrent thread, which means that you need to place a breakpoint at (or just after) the point where the variables you want to inspect become active. Whilst you hold on the breakpoint you can use the Displaytab to interact (execute code snippets, evaluate etc..) with all the variables that you can see in the Variablestab
它仅在调试中运行时才有效,并且您只能操作当前线程上下文中存在的变量,这意味着您需要在要检查的变量的位置(或之后)放置一个断点变得活跃。当您按住断点时,您可以使用“显示”选项卡与您可以在“变量”选项卡中看到的所有变量进行交互(执行代码片段、评估等)
回答by Eli Acherkan
When you've stopped at a breakpoint, you can write or paste code into the Display view, select it, and press Ctrl+Shift+Ito inspect (i.e. evaluate) the selection.
当您在断点处停止时,您可以将代码写入或粘贴到 Display 视图中,选择它,然后按Ctrl+ Shift+I来检查(即评估)选择。
回答by Christophe Roussy
I think this powerfulfeature should be used way more often.
我认为这个强大的功能应该更频繁地使用。
- In the debug perspective:
Window -> Show View -> (search for) Display
- Put a break point in your code
- Trigger the breakpoint by executing this code
- Once on the breakpoint go to the Display view
- Write some code like
myObject.getSomeData();
, you can autocomplete (Ctrl+Space) - Select the expression (code) you want to evaluate
- Use one of the many display view buttons which should now be enabled
- Save some precious time...
- 在调试角度:
Window -> Show View -> (search for) Display
- 在你的代码中放置一个断点
- 通过执行此代码触发断点
- 到达断点后,转到“显示”视图
- 编写一些代码,例如
myObject.getSomeData();
,您可以自动完成(Ctrl+Space) - 选择要计算的表达式(代码)
- 使用现在应该启用的众多显示视图按钮之一
- 节省一些宝贵的时间...
Not sure why this view is not there by default, it should be !
不知道为什么默认情况下没有这个视图,它应该是!
回答by Andrew
As of Eclipse Photon Release (4.8.0)
从 Eclipse Photon 版本 (4.8.0) 开始
This same functionality can be performed inside the the Debug Shell
. I do this by:
可以在Debug Shell
. 我这样做:
- Make sure I'm at a breakpoint in a Debug execution of some script
- Open the
Debug Shell
- Type in the code that I want to run
- Highlight the specific line of code
- Use either of the buttons for:
Execute Selected Text
, orDisplay Result of Evaluating Selected Text
- 确保我在某个脚本的调试执行中处于断点
- 打开
Debug Shell
- 输入我要运行的代码
- 突出显示特定的代码行
- 使用任一按钮:
Execute Selected Text
,或Display Result of Evaluating Selected Text
I'm including this answer because as of 2018, with the Photon Release, I was unable to get the Display view to work in any capacity or to even show up. But I was able to perform the same work through this method.
我包含这个答案是因为从 2018 年开始,随着 Photon Release,我无法让 Display 视图以任何身份工作,甚至无法显示。但是我能够通过这种方法执行相同的工作。