Eclipse debugging : Stack trace on event - java

Im trying to get the code flow of an open source platform. I have got the source code and ran the program from eclipse. The program has an option called "Run job" and I want to know where the control goes when that option is clicked. How can achieve this?

First, try to identify the control with the label "Run job".
You could do this by searching the source code in Eclipse with Search > File and then setting "Containing Text" to "Run job" and "File name patterns" to "*.java".
Probably in the same file, there is an ActionListener (or similar) added to the control that calls a method, when the control is clicked. This is the method you're looking for. (Add a breakpoint to see the flow in the debugger or try to understand it from the code.)

Apart from searching for the appropriate handlers and buttons in the source code (if you know the names), you can also enable tracing.
In your run configuration, there should be a tab for tracing. There, you'll want to enable some of the options under org.eclipse.ui that start with trace/.
You will get a lot of debug output, and there might be no trace option for the event you'd like to see. However it works well for things like keybindings (trace/keyBindings) and knowing which UI element got an event (trace/graphics). Note that some also take arguments, e.g. a commandId (something like org.eclipse.ui.edit.copy, will depend on your application).
You can find a small help text for each option here.

Related

Step Back debugging in Eclipse

sometimes when I debug in Eclipse, I found some thing wrong so I want come back and debug again, but I want to do that just for couple statements.
I saw
How to step back in Eclipse debugger?
is it possible to "go back" in java eclipse debugger like dragging the arrow in VS
and I know about Drop to frame but I can't use this to step back any line I want. I need some thing else. For example if you use debug in Visual Studio, you can drag and drop the debug arrow anywhere you want. You can bring the debugger to previous statement and debug it again. I need something like this in Eclipse but Drop to frame doesn't do that.
Thanks.
The linked answers suggest to use a third-party product to provide exactly this feature. If you don't want to do that and are not satisfied with drop to frame, there is one more option. You can set a breakpoint before the interesting place (or just drop to that frame), and then evaluate arbitrary code in this context (see Eclipse Help or this blog post).

Java with Eclipse: Debug mode enabled?

I started developing a game in Java with Eclipse. As you all know you have to debug a lot while coding. But I have the following issue:
My game is full-screen. If I run into a breakpoint it stops (like it should) and for some reason I can't switch window anymore (I am using Windows 7). I have to press Ctrl + Alt + Delete" and start the "Task manager" to be able to switch to Eclipse window and continue debugging.
So I tried to use window mode instead of full screen. Now if I run into a breakpoint the Eclipse window gets the focus (automatically) and I can debug easily.
So I thought it would be great to be in window mode, if and only if I am in debug mode, else it should be full screen.
For this I need to know if I am in debug mode or not. After reading this and this it seems like you can't check that easily, cause it depends on the VM you are using. Also it seems like the best solution is to use the Eclipse Debug/Run-Configuration and set a VM or program argument.
But how can I tell Eclipse to use this configuration only for debug mode? Or is there even a better way to determine, if debug is on or off?
It seems like the best way is to use arguments and pass them by using a Debug-Configuration and a Run-Configuration with the right values.
In Eclipse you have the possibility to add a Configuration to the Run list and the Debug list.
This can be done by going to the common tab inside the configurations and check the Debug and/or Run checkbox inside the "Display in favorite menu" section.
You can also edit the favorite list (add/remove/move entries) by clicking "Organize Favorites".
Note, that it does not prevent you from runing the Debug-Configuration or debuging the Run-Configuration.

Ecplise View flow of running program

I'm currently writing a pretty large program that calls the same methods from different places.
Now I would really like to see how the program goes from one method to another as it is running. Like a live view that shows when what method is opened (and why?). Call Hierarchy doesn't suit my needs at this point. Is there a way?
One way to follow the logic of your application is by placing breakpoints at the line of code you want your application to stop at but, to do this you'll have to setup it up in debug mode.
Every major IDE will let you do this, including Eclipse.
Have a look at this tutorial:
Java Debugging with Eclipse
Once you setup your program in debug mode you can add a breakpoint in the gutter next to the line numbers.

How do I know which method/class is called when I test java GUI in eclipse?

I am a beginner using eclipse for java programming. Recently I downloaded certain source code online and ran it in eclipse successfully. I want to learn how it runs. However, I failed to find a way to monitor the progress during the program running. For example, if I run the application and click certain button in the application GUI, how do I know which class/method is called? In other words, how can I use eclipse to monitor the process of program running?
The general answer is to use the debugger. For example, set a breakpoint in some method and then use "Debug As" instead of "Run As" to run the application within Eclipse.
Here are a couple of tutorials / articles on using the Eclipse Debugger.
http://www.vogella.com/articles/EclipseDebugging/
http://agile.csc.ncsu.edu/SEMaterials/tutorials/eclipse-debugger/
http://www.ibm.com/developerworks/library/os-ecbug/
Put a breakpoint(double click the left side of the line) on your method to be debugged and debug your program.
Simply put breakpoints in the code lines you need to look and run the application in the Debug mode then it'll wait at the relevant code lines you need to check.

Eclipse: The icons in "Display View" are all greyed out

The discussion here describes the "display view" in eclipse which allows one to to quickly evaluate java expressions. The thing is, when I open the display view the icons remain greyed out and I can't execute anything. The only icon that isn't is "clear console". The odd thing is, alot of the screenshots on the web show the same behaviour but the people posting about the feature don't mentioned it. There aren't any options in the context sensitive menu either. I'm trying it on a java project. I've tried it in the debug view and I get the same issue.
I'll provide a screenshot once my hosting is sorted.
I'm using eclipse 3.4.
To be able to use it, you're supposed to be in debug mode (set a breakpoint to freeze execution). That gives you a context, a stack frame to work in.
Once you're there, you select expressions in the display view and only then can you execute them, evaluate etc. If no text in the view is selected, none of the actions will be available.
As I understand, the purpose of the 'Display' view is to allow to evaluate expression during debug sessions. Are you trying to evaluate some expressions statically (i.e. with no running application in debug mode)?

Categories

Resources