eventfilter.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,327 行 · 第 1/3 页

C
1,327
字号
            case JDWP_REQUEST_MODIFIER(Count): {                JDI_ASSERT(filter->u.Count.count > 0);                if (--filter->u.Count.count > 0) {                    return JNI_FALSE;                }                *shouldDelete = JNI_TRUE;                break;            }                            case JDWP_REQUEST_MODIFIER(Conditional): /***                if (...  filter->u.Conditional.exprID ...) {                    return JNI_FALSE;                }***/                break;        case JDWP_REQUEST_MODIFIER(ClassMatch): {                          if (!patternStringMatch(classname,                       filter->u.ClassMatch.classPattern)) {                return JNI_FALSE;            }            break;        }        case JDWP_REQUEST_MODIFIER(ClassExclude): {                          if (patternStringMatch(classname,                       filter->u.ClassExclude.classPattern)) {                return JNI_FALSE;            }            break;        }        case JDWP_REQUEST_MODIFIER(Step):                 if (!isSameObject(env, thread, filter->u.Step.thread)) {                    return JNI_FALSE;                }                if (!stepControl_handleStep(env, thread, clazz, method)) {                    return JNI_FALSE;                }                break;                          case JDWP_REQUEST_MODIFIER(SourceNameMatch): {              char* desiredNamePattern = filter->u.SourceNameOnly.sourceNamePattern;              if (!searchAllSourceNames(env, clazz,                            desiredNamePattern) == 1) {                  /* The name isn't in the SDE; try the sourceName in the ref                    * type                   */                  char *sourceName = 0;                  jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName)                                            (gdata->jvmti, clazz, &sourceName);                  if (error == JVMTI_ERROR_NONE) {                      if (sourceName == 0 || !patternStringMatch(sourceName, desiredNamePattern)) {                        /* We have no match */                        jvmtiDeallocate(sourceName);                        return JNI_FALSE;                      }                  }                  jvmtiDeallocate(sourceName);              }              break;          }               default:             EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"Invalid filter modifier");            return JNI_FALSE;        }    }    return JNI_TRUE;}/* Determine if this event is interesting to this handler.  Do so * by checking each of the handler's filters.  Return false if any * of the filters fail, true if the handler wants this event. * Special version of filter for unloads since they don't have an * event structure or a jclass.   * * If shouldDelete is returned true, a count filter has expired * and the corresponding node should be deleted. */jboolean eventFilterRestricted_passesUnloadFilter(JNIEnv *env,                                         char *classname,                                          HandlerNode *node,                                          jboolean *shouldDelete){    Filter *filter = FILTERS_ARRAY(node);    int i;    *shouldDelete = JNI_FALSE;    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {        switch (filter->modifier) {                       case JDWP_REQUEST_MODIFIER(Count): {                JDI_ASSERT(filter->u.Count.count > 0);                if (--filter->u.Count.count > 0) {                    return JNI_FALSE;                }                *shouldDelete = JNI_TRUE;                break;            }                            case JDWP_REQUEST_MODIFIER(ClassMatch): {                       if (!patternStringMatch(classname,                         filter->u.ClassMatch.classPattern)) {                    return JNI_FALSE;                }                break;            }                        case JDWP_REQUEST_MODIFIER(ClassExclude): {                if (patternStringMatch(classname,                        filter->u.ClassExclude.classPattern)) {                    return JNI_FALSE;                }                break;            }                        default:                 EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT,"Invalid filter modifier");                return JNI_FALSE;        }    }    return JNI_TRUE;}/** * This function returns true only if it is certain that * all events for the given node in the given stack frame will * be filtered. It is used to optimize stepping. (If this * function returns true the stepping algorithm does not * have to step through every instruction in this stack frame; * instead, it can use more efficient method entry/exit * events. */jbooleaneventFilter_predictFiltering(HandlerNode *node, jclass clazz, char *classname){    JNIEnv     *env;    jboolean    willBeFiltered;    Filter     *filter;    jboolean    done;    int         count;    int         i;    willBeFiltered = JNI_FALSE;    env            = NULL;    filter         = FILTERS_ARRAY(node);    count          = FILTER_COUNT(node);    done           = JNI_FALSE;        for (i = 0; (i < count) && (!done); ++i, ++filter) {        switch (filter->modifier) {            case JDWP_REQUEST_MODIFIER(ClassOnly):                if ( env==NULL ) {                    env = getEnv();                }                if (!JNI_FUNC_PTR(env,IsAssignableFrom)(env, clazz,                                 filter->u.ClassOnly.clazz)) {                    willBeFiltered = JNI_TRUE;                    done = JNI_TRUE;                }                break;                    case JDWP_REQUEST_MODIFIER(Count): {                   /*                 * If preceeding filters have determined that events will                 * be filtered out, that is fine and we won't get here.                 * However, the count must be decremented - even if                 * subsequent filters will filter these events.  We                 * thus must end now unable to predict                 */                done = JNI_TRUE;                break;            }                            case JDWP_REQUEST_MODIFIER(ClassMatch): {                              if (!patternStringMatch(classname,                        filter->u.ClassMatch.classPattern)) {                    willBeFiltered = JNI_TRUE;                    done = JNI_TRUE;                }                break;            }                case JDWP_REQUEST_MODIFIER(ClassExclude): {                if (patternStringMatch(classname,                       filter->u.ClassExclude.classPattern)) {                    willBeFiltered = JNI_TRUE;                    done = JNI_TRUE;                }                break;            }        }    }    return willBeFiltered;}/** * Determine if the given breakpoint node is in the specified class. */jboolean eventFilterRestricted_isBreakpointInClass(JNIEnv *env, jclass clazz,                                           HandlerNode *node) {    Filter *filter = FILTERS_ARRAY(node);    int i;    for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {        switch (filter->modifier) {            case JDWP_REQUEST_MODIFIER(LocationOnly):                return isSameObject(env, clazz, filter->u.LocationOnly.clazz);        }    }    return JNI_TRUE; /* should never come here */}/***** filter set-up *****/jvmtiErroreventFilter_setConditionalFilter(HandlerNode *node, jint index,                                  jint exprID){    ConditionalFilter *filter = &FILTER(node, index).u.Conditional;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Conditional);    filter->exprID = exprID;    return JVMTI_ERROR_NONE;}jvmtiErroreventFilter_setCountFilter(HandlerNode *node, jint index,                            jint count){    CountFilter *filter = &FILTER(node, index).u.Count;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if (count <= 0) {        return JDWP_ERROR(INVALID_COUNT);    } else {        FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(Count);        filter->count = count;        return JVMTI_ERROR_NONE;    }}jvmtiError eventFilter_setThreadOnlyFilter(HandlerNode *node, jint index,                                jthread thread){    JNIEnv *env = getEnv();    ThreadFilter *filter = &FILTER(node, index).u.ThreadOnly;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if (NODE_EI(node) == EI_GC_FINISH) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }         /* Create a thread ref that will live beyond */    /* the end of this call */    saveGlobalRef(env, thread, &(filter->thread));    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(ThreadOnly);    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setLocationOnlyFilter(HandlerNode *node, jint index,                                   jclass clazz, jmethodID method,                                  jlocation location){    JNIEnv *env = getEnv();    LocationFilter *filter = &FILTER(node, index).u.LocationOnly;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if ((NODE_EI(node) != EI_BREAKPOINT) &&         (NODE_EI(node) != EI_FIELD_ACCESS) &&         (NODE_EI(node) != EI_FIELD_MODIFICATION) &&         (NODE_EI(node) != EI_SINGLE_STEP) &&         (NODE_EI(node) != EI_EXCEPTION)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    /* Create a class ref that will live beyond */    /* the end of this call */    saveGlobalRef(env, clazz, &(filter->clazz));    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(LocationOnly);    filter->method = method;    filter->location = location;    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setFieldOnlyFilter(HandlerNode *node, jint index,                                jclass clazz, jfieldID field){    JNIEnv *env = getEnv();    FieldFilter *filter = &FILTER(node, index).u.FieldOnly;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if ((NODE_EI(node) != EI_FIELD_ACCESS) &&         (NODE_EI(node) != EI_FIELD_MODIFICATION)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    /* Create a class ref that will live beyond */    /* the end of this call */    saveGlobalRef(env, clazz, &(filter->clazz));    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(FieldOnly);    filter->field = field;    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setClassOnlyFilter(HandlerNode *node, jint index,                                jclass clazz){    JNIEnv *env = getEnv();    ClassFilter *filter = &FILTER(node, index).u.ClassOnly;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if (        (NODE_EI(node) == EI_GC_FINISH) ||        (NODE_EI(node) == EI_THREAD_START) ||        (NODE_EI(node) == EI_THREAD_END)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    /* Create a class ref that will live beyond */    /* the end of this call */    saveGlobalRef(env, clazz, &(filter->clazz));    FILTER(node, index).modifier = JDWP_REQUEST_MODIFIER(ClassOnly);    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setExceptionOnlyFilter(HandlerNode *node, jint index,                                    jclass exceptionClass,                                    jboolean caught,                                   jboolean uncaught){    JNIEnv *env = getEnv();    ExceptionFilter *filter = &FILTER(node, index).u.ExceptionOnly;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if (NODE_EI(node) != EI_EXCEPTION) {         return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    filter->exception = NULL;    if (exceptionClass != NULL) {        /* Create a class ref that will live beyond */        /* the end of this call */        saveGlobalRef(env, exceptionClass, &(filter->exception));    }    FILTER(node, index).modifier =                        JDWP_REQUEST_MODIFIER(ExceptionOnly);    filter->caught = caught;    filter->uncaught = uncaught;    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setInstanceOnlyFilter(HandlerNode *node, jint index,                                   jobject instance){    JNIEnv *env = getEnv();    InstanceFilter *filter = &FILTER(node, index).u.InstanceOnly;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    filter->instance = NULL;    if (instance != NULL) {        /* Create an object ref that will live beyond          * the end of this call         */        saveGlobalRef(env, instance, &(filter->instance));    }    FILTER(node, index).modifier =                       JDWP_REQUEST_MODIFIER(InstanceOnly);    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setClassMatchFilter(HandlerNode *node, jint index,                                 char *classPattern){    MatchFilter *filter = &FILTER(node, index).u.ClassMatch;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if (        (NODE_EI(node) == EI_THREAD_START) ||        (NODE_EI(node) == EI_THREAD_END)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    FILTER(node, index).modifier =                        JDWP_REQUEST_MODIFIER(ClassMatch);    filter->classPattern = classPattern;    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setClassExcludeFilter(HandlerNode *node, jint index,                                   char *classPattern){    MatchFilter *filter = &FILTER(node, index).u.ClassExclude;    if (index >= FILTER_COUNT(node)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    if (        (NODE_EI(node) == EI_THREAD_START) ||        (NODE_EI(node) == EI_THREAD_END)) {        return AGENT_ERROR_ILLEGAL_ARGUMENT;    }    FILTER(node, index).modifier =                        JDWP_REQUEST_MODIFIER(ClassExclude);    filter->classPattern = classPattern;    return JVMTI_ERROR_NONE;}jvmtiError eventFilter_setStepFilter(HandlerNode *node, jint index,                           jthread thread, jint size, jint depth){    jvmtiError error;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?