简体   繁体   English

Eclipse - 显示完整的调用堆栈(比如它在调试器中遇到断点)而没有放入断点?

[英]Eclipse - showing full call stack (like when it hits breakpoint in debugger) without putting in breakpoints?

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. 我正在使用一个对我来说不熟悉的遗留Java应用程序,因此有一种方法可以找出它是如何工作的并且更容易找到事情,我认为在执行操作后能够获得完整的堆栈跟踪,以便能够根据特定的UI动作查看正在使用的类。 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). 我原以为这在调试器中是可能的,但似乎只有在我插入一个断点时它才有效,在这种情况下,部分目的是为了让我不必知道被调用的是什么才能插入断点第一(因为这有助于告诉我)。

I apologize if this is a basic question, I have searched on this but I'm not finding the correct answer. 如果这是一个基本问题我很抱歉,我已经搜索了这个,但我找不到正确的答案。

This doesn't directly answer your question, but maybe it will solve your problem better. 这并没有直接回答你的问题,但也许它会更好地解决你的问题。 Take a look at BTrace . 看看BTrace It lets you instrument a running Java app and insert some basic code of your own. 它允许您检测正在运行的Java应用程序并插入自己的一些基本代码。 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: 它有点类似于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程序的类中,并对跟踪的程序类进行热交换。”

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. 要尝试捕获特定操作正在执行的操作,您必须启动操作然后快速暂停所有线程。

You could always run the application with the VM arg of -verbose:class. 您始终可以使用VM arg -verbose:class运行应用程序。 You could then watch the console output and see what classes the VM is loading when you perform a particular action. 然后,您可以观察控制台输出,并在执行特定操作时查看VM正在加载的类。 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. 根据情况,这并不总是有效,但可能会有所帮助。

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). 例如,您提到它是一个Java EE Web应用程序,因此该操作可能是某种类型的servlet交互(在某种程度上)。 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. 我没有在我面前的API,但您可以在响应对象中检索输出流的方法上放置一个断点。 Once that breaks, you will know the code that's trying to service the request. 一旦中断,您将知道尝试为请求提供服务的代码。

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. 反向设计大型遗留应用程序是我经常使用UML的地方。 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. 如果您有一个可以进行逆向工程的UML工具,请使用该应用程序加载它,然后可能会仔细修剪您不关心的类,因为它们很简单或显而易见。 Arrange the diagrams in a way that helps you understand. 以有助于您理解的方式排列图表。 I've used Together, Magic Draw, and Visual Paradigm in this way. 我以这种方式使用了Together,Magic Draw和Visual Paradigm。 Together worked the best - but it was a decade ago. 一起工作最好 - 但它是在十年前。

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 ). 通过单击eclipse中的“打开调用层次结构”(左键单击所选方法或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). 此外,您始终可以通过单击“打开声明”(左键单击所选方法/类或F3)来检查定义方法/类的位置。

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

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