Remote debugging:
The eclipse IDE can remote debug your web application. Imagine being able to debug your development server from your local machine. Eclipse can help you do this. First you need to instruct your application / server to listen on a port for debug messages. That can be done using the -Xdebug flag
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787,suspend=n
This tells the JVM to listen for specific debug messages on port 8787. In eclipse open Bug Icon -> Debug configurations and select “Remote java application”. Mention the port and server address and you should now be able to remote debug the application. Make sure that the classes and source sync with each other. On a network where the bandwidth is poor, this technique will not work.
Remote java application:
Use the display view:
The debug perspective in eclipse can open up a “Display” view that allows you to dynamically enter some code for execution when you hit a breakpoint. This view is priceless. You can dynamically execute code related to the variables that are in scope. Use the icons available on the top right hand corner of the view to do this.
Display view:
Set breakpoints at different levels:
You can set class level, method level or line level breakpoints. Nothing special but once again it can save you time. Just set a breakpoint corresponding to a class declaration a method declaration or a specific line.
Set conditional breakpoints:
Breakpoints can be triggered conditionally. Simple right click on a breakpoint and select ‘Breakpoint properties” There are 3 settings that you can tweak.
- Hit count – Break only when code flow passes over this breakpoint N times.
- Condition – Break when a specific programmatic condition is reached.
- Suspend VM Vs Suspend Thread – This is useful when debugging multithreaded application. If you want to suspend only the current thread and not all threads that are running through this code flow, you can use this drop down.
Breakpoint properties:
Tweak the breakpoint:
Specify a detail formatter of your own:
Use the Variables view to mention a detailed formatter for an object type. This will display the object in question in a different format when you look it up under Variables or in an inspection window.
Open the detail formatter:
Type a detail format:
See the results in the variable window (among other places):
Use inspection windows:
Inspection windows can reveal the detailed object graph of the instance in question. Simply highlight the variable and type the shortcut ctrl+shift+i
Inspect:
Traverse the object graph:
Use all instances / references:
Use the all instances / all references option in the Variables view to determine the usage of a particular Object type at runtime. Arguably a profiler might be better suited for this sort of work, but hey, you never know when you might need it.
View all instances of an object type:
Change variable values dynamically:
You can use the Variables view to change the value of a variable dynamically. This helps to determine code flow control if you have conditional statements. You could also do the same using the Display view but the GUI helps.
Change value:
Use the drop to frame feature:
The “drop to frame” feature allows you to retrace your path after making a minor code change. The code flow goes back to the line of code you have dropped to and executes once again. You could even, say, change a database variable and drop back a few call stacks behind to retrace your steps.
Drop frame:
Thats about the list of debugging tips I know. Do you have one that could help other developers ? Drop a comment. There is one more article on eclipse productivity coming down the line. Subscribe to the RSS feed if you would like to keep up to date.