如何在 eclipse java 调试器中设置当前执行行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/191306/
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 can I set the current line of execution in the eclipse java debugger?
提问by stu
I want to force the current execution line to a specific line in the same function, possibly skipping intermediate lines. All my old school debuggers had this feature, but I can't find it in eclipse. Is there a way to do it without changing code?
我想强制当前执行行到同一函数中的特定行,可能会跳过中间行。我所有的老式调试器都有这个功能,但我在 eclipse 中找不到它。有没有办法在不更改代码的情况下做到这一点?
采纳答案by PhiLho
The first two answers seem to miss the topic, unless it is me not understanding the question.
前两个答案似乎错过了主题,除非是我不理解问题。
My understanding, a feature I searched myself, is that you want to skipa number of lines (when stepping in code) and set the program counter (to take assembly vocabulary) to the given line. It might be interesting to skip some costly object creation, see some error situations, etc. I used to do that in Visual Studio (C or C++ code).
我的理解,我自己搜索的一个功能,是你想要跳过一些行(当单步执行代码时)并将程序计数器(获取汇编词汇)设置为给定的行。跳过一些代价高昂的对象创建、查看一些错误情况等可能会很有趣。我曾经在 Visual Studio(C 或 C++ 代码)中这样做。
I haven't found that in Eclipse, nor in NetBean. It might be a limitation of JVM, or an enforcement of some policy...
我在 Eclipse 和 NetBean 中都没有找到。这可能是 JVM 的限制,或者是某些策略的强制执行...
The Run to linecommand execute, of course, all lines between the current execution position and the designated one.
该运行以线命令执行,当然,当前执行位置和指定的一个之间的所有行。
回答by Chris Noe
I too have long sought this feature, and "Run to line" is not the same thing.
我也一直在寻找这个功能,“跑到线”不是一回事。
This may well be a limitation of the JVM. Java does not implement goto, though it does have jumpstatements, like break and continue. Those are at the block level however. If this is a JVM limitation, my guess is that it is more likely due to the security architecture. Tight control of the program counteris debilitating for interlopers, like viruses -- and sadly debuggers.
这很可能是 JVM 的限制。Java 没有实现 goto,尽管它有跳转语句,比如 break 和 continue。然而,这些是在块级别。如果这是一个 JVM 限制,我的猜测是它更有可能是由于安全架构。对程序计数器的严格控制使入侵者(如病毒)和可悲的是调试器变得虚弱。
回答by Mario Ortegón
I think that is not possible in Java. The only feature that allows you to "step back" is using "drop to frame", which takes you back to the first instruction of the current frame. At least I haven't seen any debugger with this specific functionality, but I haven't been able to find on the net why is it so...
我认为这在 Java 中是不可能的。允许您“后退”的唯一功能是使用“移至帧”,它会将您带回到当前帧的第一条指令。至少我还没有看到任何具有此特定功能的调试器,但是我无法在网上找到为什么会这样......
I know the debugger in Visual C allows to change to pointer. I will keep on searching, maybe at least we will know why is like this, but it seems to be some kind of design limitation.
我知道 Visual C 中的调试器允许更改为指针。我会继续寻找,也许至少我们会知道为什么会这样,但这似乎是某种设计限制。
回答by jruel
"Run to line" appears to need the program to be running and in a paused state to use. The other option is to set a breakpoint for that line when running in debug-mode.
“运行到线”似乎需要程序正在运行并处于暂停状态才能使用。另一个选项是在调试模式下运行时为该行设置断点。
- Double-click far-left vertical bar in the source pane on the same line to add a breakpoint; or,
- Select the line and go to Run > Toggle Breakpoint.
- 在同一行的源代码窗格中双击最左侧的竖线添加断点;或者,
- 选择该行并转到运行 > 切换断点。
At least, this is in Eclipse 3.3.2.
至少,这是在 Eclipse 3.3.2 中。