Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-debug-dev] Common Questions about functionality in jdt.debug.core

>              Below is the code I use to set the MethodEntryBreakpoint.
> 
> IResource resource = unit.getResource();
> String typeName = unit.findPrimaryType().getFullyQualifiedName();
> String methodName = "stateChanged";
> String methodSig = "";
> IMethod[] meths = unit.findPrimaryType().getMethods();
> for(int i=0;i < meths.length;i++){
>     if(meths[i].getElementName().equalsIgnoreCase(methodName)){
>         methodName = meths[i].getElementName();
>         methodSig = meths[i].getSignature();
>     }
> }
> int line = 111;

This code looks reasonable - are you positive that a matching method is 
found in the for loop? (you could add a "break" statement to avoid 
searching all methods when the first match is found).

> 
> Map attributes = new HashMap(3);
> attributes.put("PATTINFO","This is just a marker explanation");;
> attributes.put(IMarker.LINE_NUMBER,"111");

You don't need to specify the LINE_NUMBER attribute, it will be set by the 
breakpoint via the line number you specify in the creation call.

> attributes.put(IMarker.MESSAGE,"This is a message for the hover");
> BreakpointUtils.addJavaBreakpointAttributes(attributes, unit);
> 
> IJavaMethodEntryBreakpoint br = 
> JDIDebugModel.createMethodEntryBreakpoint(resource,typeName, methodName, 

> methodSig, line, -1, -1,0,true,null);

Although you created an extra attributes map, you did not pass it into the 
contructor (i.e. the last argument is "null").

> 
> Is there something I need to do after this to install the breakpoint? 
> Even if I call

Since you have specified "true" for the "register" breakpoint argument in 
the creation call (second last argument), you do not need to add the 
breakpoint to the breakpoint manager manually - this will be done for you. 
When the breakpoint is added to the manager, debug targets will be 
notified and install the breakpoint. If you were to specify "false" for 
registering the breakpoint, you would need to add the breakpoint to the 
debug target manually via its IBreakpointListener inteface.


Darin


Back to the top