Eclipse - 显示完整的调用堆栈(比如它在调试器中遇到断点时)而不设置断点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6711954/
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
Eclipse - showing full call stack (like when it hits breakpoint in debugger) without putting in breakpoints?
提问by Rick
I'm working with a legacy Java app that is new to me so one way to figure out how it works and find things easier, I have thought would be to be able to get the full stack trace after I perform actions, so as to be able to see which classes are being used based on a particular UI action. I had thought this was possible in the debugger but it seems that it only works if I insert a breakpoint and in this case part of the purpose of this is so that I don't have to know what's being called to be able to insert the breakpoint first (as this would help tell me that).
我正在使用一个对我来说很新的遗留 Java 应用程序,所以一种弄清楚它是如何工作的并更容易找到事情的方法,我认为在我执行操作后能够获得完整的堆栈跟踪,以便能够根据特定的 UI 操作查看正在使用哪些类。我曾认为这在调试器中是可能的,但它似乎只有在我插入断点时才有效,在这种情况下,这样做的部分目的是这样我就不必知道正在调用什么才能插入首先断点(因为这有助于告诉我这一点)。
I apologize if this is a basic question, I have searched on this but I'm not finding the correct answer.
如果这是一个基本问题,我深表歉意,我已经对此进行了搜索,但没有找到正确的答案。
采纳答案by Ryan Stewart
This doesn't directly answer your question, but maybe it will solve your problem better. Take a look at BTrace. It lets you instrument a running Java app and insert some basic code of your own. You could, for instance, have it write out entire method call chains to help you find your way through the app. It's somewhat similar to AspectJ, but with an entirely different purpose and requiring no change in the project source:
这并不能直接回答您的问题,但也许它会更好地解决您的问题。看看BTrace。它允许您检测正在运行的 Java 应用程序并插入您自己的一些基本代码。例如,您可以让它写出整个方法调用链,以帮助您在应用程序中找到自己的方式。它有点类似于 AspectJ,但具有完全不同的目的并且不需要更改项目源:
"BTrace is a safe, dynamic tracing tool for Java. BTrace works by dynamically (bytecode) instrumenting classes of a running Java program. BTrace inserts tracing actions into the classes of a running Java program and hotswaps the traced program classes."
“BTrace 是一种安全的 Java 动态跟踪工具。BTrace 通过动态(字节码)检测正在运行的 Java 程序的类来工作。BTrace 将跟踪操作插入到正在运行的 Java 程序的类中,并热交换被跟踪的程序类。”
回答by Ed Staub
A few suggestions:
几点建议:
Some profilers will allow you to walk from any particular method up (and sometimes down) to see what's calling and being called. I've found this surprising informative about flow, even in apps I thought I knew well.
一些分析器将允许您从任何特定方法向上(有时向下)查看正在调用和被调用的内容。我发现了这个关于流程的令人惊讶的信息,即使在我认为我很熟悉的应用程序中也是如此。
For understanding the mainline flow, I don't think there's a better substitute for working interactively with a debugger. It will lead you into learning other important things. Not what you wanted to hear, I know. This presumes that you can rapidly restart the app when you miss a key off-ramp.
为了理解主线流程,我认为没有比与调试器交互工作更好的替代品了。它会引导你学习其他重要的东西。不是你想听的,我知道。这假定您可以在错过关键出口匝道时快速重新启动应用程序。
Reverse-designing large legacy apps is the one place where I use UML fairly regularly. There's too much to keep in my head to form a good big picture. If you have a UML tool that will do reverse-engineering, load it up with the app, then probably prune down hard on the classes you don't care about, because they are trivial or obvious. Arrange the diagrams in a way that helps you understand. I've used Together, Magic Draw, and Visual Paradigm in this way. Together worked the best - but it was a decade ago.
反向设计大型遗留应用程序是我经常使用 UML 的地方。有太多东西要留在我的脑海中以形成一个好的大局。如果您有一个可以进行逆向工程的 UML 工具,请将其与应用程序一起加载,然后可能会大力修剪您不关心的类,因为它们是微不足道的或显而易见的。以有助于您理解的方式排列图表。我以这种方式使用了 Together、Magic Draw 和 Visual Paradigm。在一起效果最好——但那是十年前的事了。
回答by Konstantin Komissarchik
When you are in the debugger perspective, you will see a view showing the launched processes. In that view you can tell it to pause all threads of a process. Once stopped, you will be able to browse through threads to see what they are all doing. To try to catch what a particular action is doing, you would have to start the action and then quickly pause all threads.
当您处于调试器透视图时,您将看到一个显示已启动进程的视图。在该视图中,您可以告诉它暂停进程的所有线程。一旦停止,您将能够浏览线程以查看它们都在做什么。要尝试捕捉特定操作正在执行的操作,您必须启动该操作,然后快速暂停所有线程。
回答by Konstantin Komissarchik
Another trick you can use is to figure what classes you know that have to be involved in the code path you are trying to trap. For instance, you mentioned that it's a Java EE web app and therefore the action is likely some kind of a servlet interaction (at some level). I don't have the API in front of me, but you can place a breakpoint on the method in the response object where the output stream is retrieved. Once that breaks, you will know the code that's trying to service the request.
您可以使用的另一个技巧是确定您知道哪些类必须涉及您试图捕获的代码路径。例如,您提到它是一个 Java EE Web 应用程序,因此该操作可能是某种 servlet 交互(在某种程度上)。我面前没有 API,但您可以在检索输出流的响应对象中的方法上放置断点。一旦中断,您就会知道试图为请求提供服务的代码。
回答by Neil H
You could always run the application with the VM arg of -verbose:class. You could then watch the console output and see what classes the VM is loading when you perform a particular action. This could possibly give you a starting place for where to place breakpoints. This won't always work depending on the scenario, but may be helpful.
您始终可以使用 -verbose:class 的 VM arg 运行应用程序。然后,您可以查看控制台输出并查看执行特定操作时 VM 正在加载哪些类。这可能会为您提供一个放置断点的起点。根据场景,这并不总是有效,但可能会有所帮助。
回答by Sam
You can always see where a method is called by clicking "Open Call Hierarchy" from eclipse (left click on the selected method or CTRL+ALT+H ). Also, you always can inspect where a method/class is defined by clicking "Open Declaration" (left click on the selected method/class or F3).
您始终可以通过单击 eclipse 中的“打开调用层次结构”(左键单击所选方法或 CTRL+ALT+H )来查看调用方法的位置。此外,您始终可以通过单击“打开声明”(左键单击所选方法/类或 F3)来检查方法/类的定义位置。