0

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" );
}
jni.h:
void CallVoidMethodA(jobject obj, jmethodID methodID,
         const jvalue * args) {
    functions->CallVoidMethodA(this,obj,methodID,args);
}
Yan Gao
  • 181
  • 1
  • 3
  • 11

3 Answers3

1

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.

Community
  • 1
  • 1
Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
1

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

0

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

Andro
  • 2,232
  • 1
  • 27
  • 40
  • 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 03 '11 at 19:17