Was debugging some code the other day and had some annoyance. I had to set a breakpoint in my code and then try to figure out where a problem happened by going into methods, and jump multiple steps before actually reaching the code I wanted to test. In this case the code to debug was a third party library which made the problem even harder.
I’ve used JD-Gui for decompiling code for years now. This tool usually decodes in a good manor and keeps line numbers intact so I could follow the code in JD-Gui when I debugged in Eclipse. But reaching the code I wanted to look into, often required me to follow hundreds of branches. Remembering these correctly and reach the code I wanted to test wasn’t feasible for prolonged testing.
The other day I right clicked one of the breakpoints by mistake and saw the option export/import breakpoints. This gave me the idea that I could try to export one of my breakpoints, modify it and import.
The big surprise was that this was really easy to accomplice. Most of the data exported by the tooling wasn’t actually needed to pinpoint the breakpoint. Most of the data seemed to be there as meta data for showing the breakpoint in GUI. So after testing multiple times inside Eclipse Luna I found that I could put a breakpoint into the code fetching appenders in log4j with only these lines.
<?xml version="1.0" encoding="UTF-8"?> <breakpoints> <breakpoint enabled="false" persistant="true" registered="true"> <resource path="/" type="8"/> <marker lineNumber="200" type="org.eclipse.jdt.debug.javaLineBreakpointMarker"> <attrib name="org.eclipse.jdt.debug.core.typeName" value="org.apache.log4j.Category"/> <attrib name="message" value=""/> </marker> </breakpoint> </breakpoints>
Above I’ve added the code for a breakpoint that should be disabled at start. The parser requires a resource with path and type and in this case I choose 8 because this type didn’t require any specific path.
Then we want to create a marker to tell the debugger where to stop execution. In my case I create a javaLineBreakpointMarker at line number 200 inside of the class org.apache.log4j.Category. Lastly we have a message used to display the text of the breakpoint in a more visually pleasing way.
The default display shows Classname[Linenumber] (/).