Class JDIDebugModel


  • public class JDIDebugModel
    extends Object
    Provides utility methods for creating debug targets and breakpoints specific to the JDI debug model.

    To provide access to behavior and information specific to the JDI debug model, a set of interfaces are defined which extend the base set of debug element interfaces. For example, IJavaStackFrame is declared to extend IStackFrame, and provides methods specific to this debug model. The specialized interfaces are also available as adapters from the debug elements generated from this model.

    This class provides static utility methods only.

    Restriction:
    This class is not intended to be subclassed by clients.
    Restriction:
    This class is not intended to be instantiated by clients.
    • Field Detail

      • PREF_REQUEST_TIMEOUT

        public static final String PREF_REQUEST_TIMEOUT
        Preference key for default JDI request timeout value.
      • PREF_HCR_WITH_COMPILATION_ERRORS

        public static final String PREF_HCR_WITH_COMPILATION_ERRORS
        Preference key for specifying if hot code replace should be performed when a replacement class file contains compilation errors.
      • DEF_REQUEST_TIMEOUT

        public static final int DEF_REQUEST_TIMEOUT
        The default JDI request timeout when no preference is set.
        See Also:
        Constant Field Values
      • PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION

        public static final String PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION
        Boolean preference controlling whether breakpoints are hit during an evaluation operation. If true, breakpoints will be hit as usual during evaluations. If false, the breakpoint manager will be automatically disabled during evaluations.
        Since:
        3.0
      • PREF_FILTER_BREAKPOINTS_FROM_UNRELATED_SOURCES

        public static final String PREF_FILTER_BREAKPOINTS_FROM_UNRELATED_SOURCES
        Boolean preference controlling whether to not install (filter) breakpoints for types existing multiple times in source projects and not related to the current debug session.
        Since:
        3.10
      • PREF_SHOW_STEP_RESULT

        public static final String PREF_SHOW_STEP_RESULT
        Preference key for specifying if the value returned or thrown should be displayed as variable after a "step return" or "step over" (if supported by the vm)
        Since:
        3.11
      • PREF_SHOW_STEP_TIMEOUT

        public static final String PREF_SHOW_STEP_TIMEOUT
        Preference key for specifying if the timeout (in ms) after which the return method result of a step operation is not observed any longer (0 means no timeout, a negative value means: simulate a timeout condition).
        Since:
        3.12
    • Method Detail

      • newDebugTarget

        public static IDebugTarget newDebugTarget​(ILaunch launch,
                                                  com.sun.jdi.VirtualMachine vm,
                                                  String name,
                                                  IProcess process,
                                                  boolean allowTerminate,
                                                  boolean allowDisconnect)
        Creates and returns a debug target for the given VM, with the specified name, and associates the debug target with the given process for console I/O. The allow terminate flag specifies whether the debug target will support termination (ITerminate). The allow disconnect flag specifies whether the debug target will support disconnection ( IDisconnect). Launching the actual VM is a client responsibility. By default, the target VM will be resumed on startup. The debug target is added to the given launch.
        Parameters:
        launch - the launch the new debug target will be contained in
        vm - the VM to create a debug target for
        name - the name to associate with the VM, which will be returned from IDebugTarget.getName. If null the name will be retrieved from the underlying VM.
        process - the process to associate with the debug target, which will be returned from IDebugTarget.getProcess
        allowTerminate - whether the target will support termination
        allowDisconnect - whether the target will support disconnection
        Returns:
        a debug target
        Since:
        2.0
        See Also:
        ITerminate, IDisconnect
      • newDebugTarget

        public static IDebugTarget newDebugTarget​(ILaunch launch,
                                                  com.sun.jdi.VirtualMachine vm,
                                                  String name,
                                                  IProcess process,
                                                  boolean allowTerminate,
                                                  boolean allowDisconnect,
                                                  boolean resume)
        Creates and returns a debug target for the given VM, with the specified name, and associates the debug target with the given process for console I/O. The allow terminate flag specifies whether the debug target will support termination (ITerminate). The allow disconnect flag specifies whether the debug target will support disconnection ( IDisconnect). The resume flag specifies if the target VM should be resumed on startup (has no effect if the VM was already running when the connection to the VM was established). Launching the actual VM is a client responsibility. The debug target is added to the given launch.
        Parameters:
        launch - the launch the new debug target will be contained in
        vm - the VM to create a debug target for
        name - the name to associate with the VM, which will be returned from IDebugTarget.getName. If null the name will be retrieved from the underlying VM.
        process - the process to associate with the debug target, which will be returned from IDebugTarget.getProcess
        allowTerminate - whether the target will support termination
        allowDisconnect - whether the target will support disconnection
        resume - whether the target is to be resumed on startup. Has no effect if the target was already running when the connection to the VM was established.
        Returns:
        a debug target
        Since:
        2.0
        See Also:
        ITerminate, IDisconnect
      • getPluginIdentifier

        public static String getPluginIdentifier()
        Returns the identifier for the JDI debug model plug-in
        Returns:
        plug-in identifier
      • removeHotCodeReplaceListener

        public static void removeHotCodeReplaceListener​(IJavaHotCodeReplaceListener listener)
        Unregisters the given listener for hot code replace notifications. Has no effect if an identical listener is not already registered.
        Parameters:
        listener - hot code replace listener
        Since:
        2.0
        See Also:
        IJavaHotCodeReplaceListener
      • addJavaBreakpointListener

        public static void addJavaBreakpointListener​(IJavaBreakpointListener listener)
        Registers the given listener for breakpoint notifications. Has no effect if an identical listener is already registered.
        Parameters:
        listener - breakpoint listener
        Since:
        2.0
        See Also:
        IJavaBreakpointListener
      • removeJavaBreakpointListener

        public static void removeJavaBreakpointListener​(IJavaBreakpointListener listener)
        Unregisters the given listener for breakpoint notifications. Has no effect if an identical listener is not already registered.
        Parameters:
        listener - breakpoint listener
        Since:
        2.0
        See Also:
        IJavaBreakpointListener
      • createLineBreakpoint

        public static IJavaLineBreakpoint createLineBreakpoint​(IResource resource,
                                                               String typeName,
                                                               int lineNumber,
                                                               int charStart,
                                                               int charEnd,
                                                               int hitCount,
                                                               boolean register,
                                                               Map<String,​Object> attributes)
                                                        throws CoreException
        Creates and returns a line breakpoint in the type with the given name, at the given line number. The marker associated with the breakpoint will be created on the specified resource. If a character range within the line is known, it may be specified by charStart/charEnd. If hitCount is > 0, the breakpoint will suspend execution when it is "hit" the specified number of times.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        typeName - the fully qualified name of the type the breakpoint is to be installed in. If the breakpoint is to be installed in an inner type, it is sufficient to provide the name of the top level enclosing type. If an inner class name is specified, it should be formatted as the associated class file name (i.e. with $). For example, example.SomeClass$InnerType, could be specified, but example.SomeClass is sufficient.
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a line breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
        Since:
        2.0
      • createPatternBreakpoint

        @Deprecated
        public static IJavaPatternBreakpoint createPatternBreakpoint​(IResource resource,
                                                                     String sourceName,
                                                                     String pattern,
                                                                     int lineNumber,
                                                                     int charStart,
                                                                     int charEnd,
                                                                     int hitCount,
                                                                     boolean register,
                                                                     Map<String,​Object> attributes)
                                                              throws CoreException
        Deprecated.
        use createStratumBreakpoint instead
        Creates and returns a pattern breakpoint for the given resource at the given line number, which is installed in all classes whose fully qualified name matches the given pattern. If hitCount > 0, the breakpoint will suspend execution when it is "hit" the specified number of times.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        sourceName - the name of the source file in which the breakpoint is set, or null. When specified, the pattern breakpoint will install itself in classes that have a source file name debug attribute that matches this value, and satisfies the class name pattern.
        pattern - the class name pattern in which the pattern breakpoint should be installed. The pattern breakpoint will install itself in every class which matches the pattern.
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a pattern breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
      • createStratumBreakpoint

        public static IJavaStratumLineBreakpoint createStratumBreakpoint​(IResource resource,
                                                                         String stratum,
                                                                         String sourceName,
                                                                         String sourcePath,
                                                                         String classNamePattern,
                                                                         int lineNumber,
                                                                         int charStart,
                                                                         int charEnd,
                                                                         int hitCount,
                                                                         boolean register,
                                                                         Map<String,​Object> attributes)
                                                                  throws CoreException
        Creates and returns a line breakpoint identified by its source file name and/or path, and stratum that it is relative to.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        stratum - the stratum in which the source name, source path and line number are relative, or null. If null or if the specified stratum is not defined for a type, the source name, source path and line number are relative to the type's default stratum.
        sourceName - the simple name of the source file in which the breakpoint is set, or null. The breakpoint will install itself in classes that have a source file name debug attribute that matches this value in the specified stratum, and satisfies the class name pattern and source path attribute. When null, the source file name debug attribute is not considered.
        sourcePath - the qualified source file name in which the breakpoint is set, or null. The breakpoint will install itself in classes that have a source file path in the specified stratum that matches this value, and satisfies the class name pattern and source name attribute. When null, the source path attribute is not considered.
        classNamePattern - the class name pattern to which the breakpoint should be restricted, or null. The breakpoint will install itself in each type that matches this class name pattern, with a satisfying source name and source path. Patterns may begin or end with '*', which matches 0 or more characters. A pattern that does not contain a '*' is equivalent to a pattern ending in '*'. Specifying null, or an empty string is the equivalent to "*". Multiple patterns can be specified by delimiting the patterns with a comma - e.g. "x.y.z,a.b.c". When multiple patterns are specified, The breakpoint will install itself in each of the types that match any of the specified class pattern, with a satisfying source name and source path.
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file (stratum) in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a stratum breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
        Since:
        3.0
      • createTargetPatternBreakpoint

        public static IJavaTargetPatternBreakpoint createTargetPatternBreakpoint​(IResource resource,
                                                                                 String sourceName,
                                                                                 int lineNumber,
                                                                                 int charStart,
                                                                                 int charEnd,
                                                                                 int hitCount,
                                                                                 boolean register,
                                                                                 Map<String,​Object> attributes)
                                                                          throws CoreException
        Creates and returns a target pattern breakpoint for the given resource at the given line number. Clients must set the class name pattern per target for this type of breakpoint. If hitCount > 0, the breakpoint will suspend execution when it is "hit" the specified number of times.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        sourceName - the name of the source file in which the breakpoint is set, or null. When specified, the pattern breakpoint will install itself in classes that have a source file name debug attribute that matches this value, and satisfies the class name pattern.
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a target pattern breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
      • createExceptionBreakpoint

        public static IJavaExceptionBreakpoint createExceptionBreakpoint​(IResource resource,
                                                                         String exceptionName,
                                                                         boolean caught,
                                                                         boolean uncaught,
                                                                         boolean checked,
                                                                         boolean register,
                                                                         Map<String,​Object> attributes)
                                                                  throws CoreException
        Creates and returns an exception breakpoint for an exception with the given name. The marker associated with the breakpoint will be created on the specified resource. Caught and uncaught specify where the exception should cause thread suspensions - that is, in caught and/or uncaught locations. Checked indicates if the given exception is a checked exception.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        exceptionName - the fully qualified name of the exception for which to create the breakpoint
        caught - whether to suspend in caught locations
        uncaught - whether to suspend in uncaught locations
        checked - whether the exception is a checked exception (i.e. compiler detected)
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation or null if none.
        Returns:
        an exception breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
        Since:
        2.0
      • createWatchpoint

        public static IJavaWatchpoint createWatchpoint​(IResource resource,
                                                       String typeName,
                                                       String fieldName,
                                                       int lineNumber,
                                                       int charStart,
                                                       int charEnd,
                                                       int hitCount,
                                                       boolean register,
                                                       Map<String,​Object> attributes)
                                                throws CoreException
        Creates and returns a watchpoint on a field with the given name in a type with the given name. The marker associated with the breakpoint will be created on the specified resource. If hitCount > 0, the breakpoint will suspend execution when it is "hit" the specified number of times.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        typeName - the fully qualified name of the type the breakpoint is to be installed in. If the breakpoint is to be installed in an inner type, it is sufficient to provide the name of the top level enclosing type. If an inner class name is specified, it should be formatted as the associated class file name (i.e. with $). For example, example.SomeClass$InnerType, could be specified, but example.SomeClass is sufficient.
        fieldName - the name of the field on which to suspend (on access or modification)
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a watchpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The CoreException's status contains the underlying exception responsible for the failure.
        Since:
        2.0
      • createMethodBreakpoint

        public static IJavaMethodBreakpoint createMethodBreakpoint​(IResource resource,
                                                                   String typePattern,
                                                                   String methodName,
                                                                   String methodSignature,
                                                                   boolean entry,
                                                                   boolean exit,
                                                                   boolean nativeOnly,
                                                                   int lineNumber,
                                                                   int charStart,
                                                                   int charEnd,
                                                                   int hitCount,
                                                                   boolean register,
                                                                   Map<String,​Object> attributes)
                                                            throws CoreException
        Creates and returns a method breakpoint with the specified criteria.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        typePattern - the pattern specifying the fully qualified name of type(s) this breakpoint suspends execution in. Patterns are limited to exact matches and patterns that begin or end with '*'.
        methodName - the name of the method(s) this breakpoint suspends execution in, or null if this breakpoint does not suspend execution based on method name
        methodSignature - the signature of the method(s) this breakpoint suspends execution in, or null if this breakpoint does not suspend execution based on method signature
        entry - whether this breakpoint causes execution to suspend on entry of methods
        exit - whether this breakpoint causes execution to suspend on exit of methods
        nativeOnly - whether this breakpoint causes execution to suspend on entry/exit of native methods only
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a method breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
        Since:
        2.0
      • createMethodEntryBreakpoint

        public static IJavaMethodEntryBreakpoint createMethodEntryBreakpoint​(IResource resource,
                                                                             String typeName,
                                                                             String methodName,
                                                                             String methodSignature,
                                                                             int lineNumber,
                                                                             int charStart,
                                                                             int charEnd,
                                                                             int hitCount,
                                                                             boolean register,
                                                                             Map<String,​Object> attributes)
                                                                      throws CoreException
        Creates and returns a method entry breakpoint with the specified criteria. A method entry breakpoint will only be installed for methods that have executable code (i.e. will not work for native methods).
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        typeName - the fully qualified name of type this breakpoint suspends execution in.
        methodName - the name of the method this breakpoint suspends execution in
        methodSignature - the signature of the method this breakpoint suspends execution in
        lineNumber - the lineNumber on which the breakpoint is set - line numbers are 1 based, associated with the source file in which the breakpoint is set
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        hitCount - the number of times the breakpoint will be hit before suspending execution - 0 if it should always suspend
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation, or null if none.
        Returns:
        a method entry breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
        Since:
        2.0
      • lineBreakpointExists

        public static IJavaLineBreakpoint lineBreakpointExists​(String typeName,
                                                               int lineNumber)
                                                        throws CoreException
        Returns a Java line breakpoint that is already registered with the breakpoint manager for a type with the given name at the given line number.
        Parameters:
        typeName - fully qualified type name
        lineNumber - line number
        Returns:
        a Java line breakpoint that is already registered with the breakpoint manager for a type with the given name at the given line number or null if no such breakpoint is registered
        Throws:
        CoreException - if unable to retrieve the associated marker attributes (line number).
      • lineBreakpointExists

        public static IJavaLineBreakpoint lineBreakpointExists​(IResource resource,
                                                               String typeName,
                                                               int lineNumber)
                                                        throws CoreException
        Returns a Java line breakpoint that is already registered with the breakpoint manager for a type with the given name at the given line number in the given resource.
        Parameters:
        resource - the resource
        typeName - fully qualified type name
        lineNumber - line number
        Returns:
        a Java line breakpoint that is already registered with the breakpoint manager for a type with the given name at the given line number or null if no such breakpoint is registered
        Throws:
        CoreException - if unable to retrieve the associated marker attributes (line number).
        Since:
        3.1
      • getPreferences

        @Deprecated
        public static Preferences getPreferences()
        Deprecated.
        the Preferences class has been deprecated, use the IEclipsePreferences accessors instead
        Returns the preference store for this plug-in or null if the store is not available.

        The Preferences class has been deprecated and clients should directly be using the InstanceScope node for JDIDebugPlugin rather than this convenience method.

        For example:
         IEclipsePreferences node = InstanceScope.INSTANCE.getNode(JDIDebugPlugin.getUniqueIdentifier());
         if(node != null) {
                ...
         }
         
        Returns:
        the preference store for this plug-in
        Since:
        2.0
      • savePreferences

        @Deprecated
        public static void savePreferences()
        Deprecated.
        the Preferences class has been deprecated, use the IEclipsePreferences accessors instead
        Saves the preference store for this plug-in.

        The Preferences class has been deprecated and clients should directly be using the InstanceScope node for JDIDebugPlugin rather than this convenience method.

        For example:
         IEclipsePreferences node = InstanceScope.INSTANCE.getNode(JDIDebugPlugin.getUniqueIdentifier());
         if(node != null) {
                try {
                        node.flush();
                } catch (BackingStoreException e) {
                        log(e);
                }
         }
         
        Since:
        2.0
      • createClassPrepareBreakpoint

        public static IJavaClassPrepareBreakpoint createClassPrepareBreakpoint​(IResource resource,
                                                                               String typeName,
                                                                               int memberType,
                                                                               int charStart,
                                                                               int charEnd,
                                                                               boolean register,
                                                                               Map<String,​Object> attributes)
                                                                        throws CoreException
        Creates and returns a class prepare breakpoint for a type with the given name. The marker associated with the breakpoint will be created on the specified resource.
        Parameters:
        resource - the resource on which to create the associated breakpoint marker
        typeName - the fully qualified name of the type for which to create the breakpoint
        memberType - one of TYPE_CLASS or TYPE_INTERFACE
        charStart - the first character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        charEnd - the last character index associated with the breakpoint, or -1 if unspecified, in the source file in which the breakpoint is set
        register - whether to add this breakpoint to the breakpoint manager
        attributes - a map of client defined attributes that should be assigned to the underlying breakpoint marker on creation or null if none.
        Returns:
        a class prepare breakpoint
        Throws:
        CoreException - If this method fails. Reasons include:
        • Failure creating underlying marker. The exception's status contains the underlying exception responsible for the failure.
        Since:
        3.0