Search code examples
c++visual-studiodebuggingjava-native-interfacenative

Conditional breakpoint triggers when it should not


I am investigating an exception that crashes the JVM, due to an error happening in native code. To do so I attach VS to the javaw process and debug functions that are relevant to my problem.

The function I am currently looking at looks as follows:

JNIEXPORT void JNICALL Java_org_bytedeco_javacpp_BoolPointer_allocateArray(JNIEnv* env, jobject obj, jlong arg0) {
    bool* rptr = new (std::nothrow) bool[arg0];
    jlong rcapacity = arg0;
    JavaCPP_initPointer(env, obj, rptr, rcapacity, rptr, &JavaCPP_org_bytedeco_javacpp_BoolPointer_deallocateArray);
}

This is JNI generated code to enable communication between Java and native code.

Since I suspect a certain condition to trigger unhandled exceptions that eventually cause the JVM to hard-crash, a breakpoint is used, to investigate the function shown above.

The breakpoint is conditional and holds the following condition:

"arg0 < 1" is "True"

It must trigger on values of one or negative values only. Apparently I am setting this up incorrectly, because the breakpoint triggers repeatedly on arg0 values, such as 3178311.

First I thought of an overflow with VS incorrectly converting the value in the Local window, where the variables are displayed on debug. However there were values as low as 8900 which makes this idea unlikely.

Also in the past I have noticed, that sometimes values do not refresh immediately, so I am always stepping through the function, when a breakpoint triggers, however the values remain consistently larger than 0.

What am I doing incorrectly? Why is my breakpoint triggering? Does VS resolve arg0 properly?

Thank you.


Solution

  • If you place the breakpoint on the first line of your code, the values of the parameters are not yet initialized in VS (this also happens if you step into functions manually). Put the breakpoint on the second line (anywhere after the opening brace) and it might work.