Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug JNI/C library?

We have system here that uses Java JNI to call a function in a C library. Everything running on Solaris.

I have a problem somewhere with string encoding. An arabic character is returned by the function written in C, but the JNI methods receives a string with another encoding. I already tried setting $NLS_LANG, and the vm parameter for encoding the same way, but nothing has worked. So I need to be able to debug the C code and the Java JNI together.

what is the best way to debug it?

like image 873
hooray Avatar asked May 26 '09 14:05

hooray


People also ask

What is JNI library?

JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).


1 Answers

The dbx debugger (part of Sun Studio) can attach to a JVM process and let you single step between Java code and native code. The functionality went by the code name "jdbx", although it's all part of dbx. It hasn't been heavily promoted, so it might have bugs. There were issues when the IDE had two debug engines both handling Java, but using the command line dbx avoids those issues.

Of course, there are probably lots of more conventional ways to debug your specific problem without necessarily using source level debugging that can mix the Java and C code.

like image 111
Chris Quenelle Avatar answered Oct 20 '22 18:10

Chris Quenelle