Take the 2-minute tour ×

there, I have a C++ function call into Java module like this. My question is how to debug into the java code? In the program, there is a "JNI_CreateJavaVM()" function call to create the VM and load Java class into it. And I step into below code with GDB. This is really a trick to me. Please give me some idea. Thanks very much!

void functions::call( jobject jo, const Parameter_list& parameter_list ) const
    Env env;
    env->CallVoidMethodA( jo, id(), JVALUES_CAST(parameter_list.jvalue_array()) );
    if( env->ExceptionCheck() )  env.throw_java( "CallVoidMethodA" );
void CallVoidMethodA(jobject obj, jmethodID methodID,
         const jvalue * args) {
share|improve this question

3 Answers 3

i am assuming that your manline is in c++ ?

if so, this is fairly straightforward:

modify your code so that the jvm is invoked with debug options, something like .... agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=60666

start your program with gdb, or without if you dont want to debug your c++ code. when your c++ code launces the jvm it will start suspended.

at that point attach the java debugger, with your java source and start debugging.

despite some complexity, this is just a standard debugging scenario (well documneted elsewhere). what differes is how your jvm gets launched. all debugging features should work for you, including in place code replacement, reset stack cycle

share|improve this answer

If you pass the right options to JNI_CreateJavaVM() then the JVM will be debuggable with a Java debugger.

Do not attempt to debug into the JVM with GDB; that way lies insanity.

share|improve this answer
I 100% agree :) –  Andrej Bratoz Nov 3 '11 at 22:11

I am quite sure that you cannot do that using GDB. Use a Java debugger to debug the Java code.

share|improve this answer
If the JVM based on C/C++, I will be able to go as close as possible to java thread in it. May be I should go another way to attach to JVM with JDB and break somewhere to see how JVM running that call. Not really clear how to do that still google and look for clue. –  Yan Gao Nov 3 '11 at 19:17

Your Answer


