简体   繁体   English

Eclipse:如何在调试时强制执行特定的java语句?

[英]Eclipse: How to force execute a particular java statement while debugging?

I have searched and found that indeed Eclipse does not support this 'direct' feature. 我搜索过并发现Eclipse确实不支持这种“直接”功能。 But, Did I stil miss something? 但是,我是否还想念一些东西? and Is it present in other IDEs? 它是否存在于其他IDE中?

Let me elaborate my question more - 让我详细说明我的问题 -

if a statement falls under execution flow based on an expression evaluation, then why can't we force execute it? 如果声明属于基于表达式评估的执行流程,那么为什么我们不能强制执行它? (without the execution of the expression). (没有执行表达式)。

For example consider this - 例如考虑这个 -

... if(bool returnsABoolean) { 
<execute some statement>; 
} 
... 

Can the execution of 'if' be skipped and the statement be executed as a 'next statement'? 可以跳过执行'if'并将语句作为'next statement'执行吗? (I obviously can control the value of 'returnAsBoolean' in the Variables view; but can I not skip (in a controlloed manner) all the statements until a particular statement in the execution?) (我显然可以在Variables视图中控制'returnAsBoolean'的值;但是我可以不跳过(以控制方式)所有语句,直到执行中的特定语句?)

Highlight the code you want to run and right-click/Execute or press Ctrl + U . 突出显示要运行的代码,然后右键单击/执行或按Ctrl + U.

Alternatively to "Execute", use "Display" ( Ctrl + Shift + D ) or "Inspect" ( Ctrl + Shift + I ) to see the result. 或者“执行”,使用“显示”( Ctrl + Shift + D )或“检查”( Ctrl + Shift + I )查看结果。

Debugging allows you to run a program interactively while watching the source code and the variables during the execution. Debugging允许您以交互方式运行程序,同时在执行期间查看源代码和变量。

So debugging is nothing but executing program but inspecting the elements during execution but you can not jump into something which is not there in execution. 所以调试只不过是执行程序而是在执行期间检查元素但是你不能跳进执行中没有的东西。

You can use keyboard buttons F5 , F6 , F8 etc. (For Eclipse) and other Shortcuts during debugging for your convinience but you can't jump to something directly which is not in the execution sequence. 您可以在调试过程中使用键盘按钮F5F6F8等(对于Eclipse)和其他快捷方式 ,但是您不能直接跳转到不在执行顺序中的内容。

Debugging Shortcuts: 调试快捷方式:

F5 Step into F5步入
F6 Step over F6退一步
F8 Resume and will take you to the break point F8 恢复并将带您到断点
Ctrl + Shift + B Toggle breakpoint Ctrl + Shift + B切换断点
Ctrl + Shift + D Display Info of current statement Ctrl + Shift + D显示当前语句的信息
Ctrl + Shift + I Inspect the selected element Ctrl + Shift + I检查所选元素

You can Skip some code by the use of breakpoint you can directly jump to specific point and avoid debugging of code which you believe works fine.Or you can jump out code snippet if you want to. 您可以通过使用断点来跳过一些代码,您可以直接跳转到特定点并避免调试您认为正常工作的代码。如果您愿意,可以跳出代码段。

Looks like you want the 'Display' view - in the Debug perspective, do : Window -> ShowView -> Display. 看起来你想要'显示'视图 - 在Debug透视图中,执行:Window - > ShowView - > Display。

You can enter Java statements to execute there (you have to select the bit of text each time that you want to execute) 您可以输入Java语句来执行(每次要执行时都必须选择文本位)

http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdisplay%2Fref-display_view.htm http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdisplay%2Fref-display_view.htm

The question really was to set the Instruction pointer at will. 问题实际上是随意设置指令指针。 This has been discussed and through url's i pasted on the comments above - this is not an eclipse feature (yet). 这已经讨论过并通过我在上面评论中粘贴的url - 这不是一个日食功能(尚未)。

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

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