Setting breakpoints for unloaded classes.

How do I set a breakpoint for a particular line in a class that has not been loaded?how do I get the Location to use createBreakpointRequest with out having the class loaded?
[195 byte] By [jasonrickabaugh] at [2007-9-30 4:41:56]
# 1

Hey Jason,

After spending over a year developing a java debugger using the JPDA, it's my opinion that the best way to build a debugger using the JPDA is by creating Manager classes.

Being able to let the user set breakpoints before a reference type is prepared (notified by a ClassPrepareEvent), or even before the target VM is started (notified by a VMStartEvent) involves having to maintain a list of all the breakpoints the user would like.

In my debugger, the user can click on any line of source code, and in the mouseClicked event handler code, I record the line number and file of the line of source code that was clicked on.

I have something like ..

public void mouseClicked(MouseEvent mouseEvent)

{

int row = this.sourceCodeTable.getSelectedRow();

int lineNumber = row + 1;

...

if (BreakpointManager.hasBreakpointRequest(file, lineNumber))

{

UnpreparedBreakpointRequest ubr = BreakpointManager.getBreakpointRequest(file, lineNumber);

if (ubr.isEnabled()) ubr.disable();

else ubr.enable();

}

else BreakpointManager.createBreakpointRequest(file, lineNumber);

...

Whenever you make a graphical debugger, expect a lot of GUI programming. Getting breakpoint glyphs to change involves a bit of work.

Whenever a ClassPrepareEvent is served from the EventQueue, I pass the ClassPrepareEvent to the BreakpointManager. The BreakpointManager gets the ReferenceType from the ClassPrepareEvent, and from the ReferenceType, the source file is retreived (through the use of referenceType.sourceName(), and VirtualMachine.classPath()). With the source file, I retrieve the list of user-defined breakpoints from a HashMap looked after by the BreakpointManager and iteratively, retrieve the locations using the lineNumber stored in each of the user-defined breakpoints, accessing the location from referenceType.locationsOfLine().get(0), and then creating a "real" BreakpointRequest using the EventManager.

It took me a lot of work to just handle being able to create, disable, enable, and delete breakpoint requests both online and offline. But again, the real lesson learnt is that without using the Manager software pattern for all types of events (BreakpointManager, WatchpointManager, et cetera), expect to get a lot of design problems later on.

Daniel_Rowley at 2007-7-1 14:27:45 > top of Java-index,Archived Forums,Debugging Tools and Techniques...