Mixing Java & C++ in one Eclipse project and debugging the crap out of it.

While porting the audio framework i wrote for the onset detection tutorial to C++ i wondered wheter i can mix Java and C++ projects in Eclipse. The goal was it to have both sources in a single Eclipse project, have the C++ code automatically compile and produce a shared library to be used for JNI stuff. I came up with a pretty simple solution using Eclipse, the CDT plugin as well as MinGW on Windows. For Linux it works the same, when you want to do cross plattform JNI stuff you will do a little extra work.

So here’s what we learn in this article:

  • Install and setup MinGW on Windows
  • Install CDT for Eclipse
  • Create a Java project with a simple class that has a single native method
  • Add a CDT C++ nature to the java project so we can create a shared library that contains the implementation of the native method
  • Debug both the Java code as well as the C++ Code in Eclipse
  • Profit!

First of let’s start with installing MinGW. MinGW is a port of the GNU compiler suite for Windows 32-bit (a 64-bit version is available too, albeit a it experimental). You can find a handy installer at http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/. Once downloaded simply execute it and install MinGW to some directory. When you are asked what components to install make sure you check “g++ compiler” otherwise we’ll only have the C compiler available. Now that MinGW is installed we have to install another little thing called gdb. For some reason the MinGW installer does not offer an option to install the MinGW version of gdb so we have to do that manually. Download the tar.gz file from http://sourceforge.net/projects/mingw/files/GNU%20Source-Level%20Debugger/GDB-7.0.50.20100202/gdb-7.0.50.20100202-mingw32-bin.tar.gz/download. Once downloaded extract the content of the file. You’ll end up with a bin/ and a share/ directory. Copy those into the directory of your MinGW install (for me that was c:/MinGW for example). The last thing we have to do is point the PATH environment variable to the MinGW/bin directory so gcc (the compiler) and gdb (the debugger) are available system wide. If you are not sure how to do this here’s a guide how to do that on Windows 7, it’s nearly the same on Vista and XP. Just add “;C:\Mingw\bin” to the system variable Path. To verify that everything works correctly open up a console window and type in “gcc” and “gdb”. The first call will tell you that there’s no input files, the second will start the prompt of gdb which you can exit via typing q+enter. Now we’re done with MinGW, on to CDT.

CDT is an Eclipse plugin which allows you to create C/C++ projects in Eclipse as well as running produced programs and debugging them. Apart from that it features all those handy features you are used to in Java under Eclipse like code completion, refactoring and so on. To install CDT simply click Help->Install New Software in Eclipse. In the dialog appearing click the Add button and enter cdt in the first field and the address “http://download.eclipse.org/tools/cdt/releases/galileo”. Back in the original dialog select “CDT Main Features” as well as “CDT Optional Features” and press next. Press next and finish a couple more time than grab yourself a cup of coffee and wait. The CDT server is kinda slow today :). After having installed the plugin Eclipse will ask you to restart it, so we do that (we really do! It’s vital!).

Now that CDT is installed we create a new Java Project, i called mine jnidemo. Next we create a new package to place our Java class into, i called mine com.badlogic.jnidemo. Create a new Java class in that package and call it JNIDemo. The implementation of JNIDemo looks like this:

When we execute this we get an error something like “Exception in thread “main” java.lang.UnsatisfiedLinkError: com.badlogic.jnidemo.JNIDemo.add(II)I”. The JVM is kindly telling us that we are stupid and didn’t provide it with the implementation of the native JNIDemo.add() method. That’s what we are going to implement now in C++.

Here comes the magic. In order to mix Java and C++ in a single Eclipse project we have to give our Java Project a C++ nature. This is achied by right-clicking the project in the package explorer, selecting “New” and then “Other”. A new dialog pops up from where we select “C/C++” -> “Convert to a C/C++ Project”.

In the next dialog we select “Shared Library” as the project type and “MinGW GCC” as the tool chain.

After clicking “Finish” you’ll be asked wheter you want to open the C/C++ perspective. Click “Yes” to open it and be amazed by the new C/C++ perspective that CDT offers you! Now we want to add the C++ code that implements our native method. First we have to create a source folder to place our C++ files in. We do this by right clicking the project, select “New” and then “Source Folder” i named mine “jni”.

Now we are ready to generate the C++ header file for our Java class. This is done via the tool “javah” on the command line. Javah is part of the Java JDK that you must have installed already to do something useful in Eclipse. You also need to put the bin/ directory of your JDK in PATH environment variable, as you have done with the MinGW bin/ directory. That makes all the Java JDK tools available on the command line, like javac and so on. Now open a console and change to the jnidemo folder. To generate the header file invoke javah as follows:

Back in eclipse we refresh the project and get a new file in the jni/ folder called JNIDemo.h. From this we copy the function signature to a new file in the same folder we call JNIDemo.cpp. Here’s the code in that file:

Ahhh, C++ how i missed you. Now let’s try to build our shared library that contains this awesome native method. For this we have to click on the hammer icon which is available in the C/C++ perspective (which we still haven’t left, right?). Here’s what we get when we do that:


**** Build of configuration Debug for project jnidemo ****

**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ojni\JNIDemo.o ..\jni\JNIDemo.cpp
In file included from ..\jni\JNIDemo.cpp:7:
..\jni\JNIDemo.h:2:17: jni.h: No such file or directory
In file included from ..\jni\JNIDemo.cpp:7:
..\jni\JNIDemo.h:15: error: JNIEXPORT' does not name a type
..\jni\JNIDemo.cpp:9: error:
JNIEXPORT’ does not name a type
Build error occurred, build is stopped
Time consumed: 82 ms.

Well, it seems we are missing an include file, namely “jni.h”. This file is provided by the JDK installation and is located in $JDK_HOME/include. In my case $JDK_HOME is “c:\Program Files (x86)\Java\jdk1.6.0_18\”, go figure out what it is on your machine, i’ll wait here… Welcome back. Now what we have to do is tell the C++ compiler to use this directory when searching for header files. For this we right-click the project and then click on properties. In the dialog click on “C/C++ Builder” in the left tree view and select “Settings” in the same tree view. In the right part of the window click on “GCC C++ Compiler/Directories”. Next add the $JDK_HOME/include directory as well as the $JDK_HOME/include/win32 directory. I hardcoded the $JDK_HOME path for simplicity, here’s how it looks:

Close the dialog and rebuild the project. Here’s the output:

**** Build of configuration Debug for project jnidemo ****

**** Internal Builder is used for build ****
g++ -Ic:\Program Files (x86)\Java\jdk1.6.0_18\include\win32 -Ic:\Program Files (x86)\Java\jdk1.6.0_18\include -O0 -g3 -Wall -c -fmessage-length=0 -ojni\JNIDemo.o ..\jni\JNIDemo.cpp
g++ -shared -olibjnidemo.dll jni\JNIDemo.o
Build complete for project jnidemo
Time consumed: 364 ms.

Awesome! We just build a shared library that contains the implementation of the native method JNIDemo.add(). The shared library is called libjnidemo.dll and located in the “Debug” folder of our project. Now all we have to do is load this library in the JNIDemo class so that Java knows where to find the native library. Here’s the modified code:

In the static block we call System.loadLibrary with the shared libraries name minus the suffix. Let’s start the JNIDemo class and see what it outputs:


java.lang.UnsatisfiedLinkError: no libjnidemo in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.badlogic.jnidemo.JNIDemo.(JNIDemo.java:7)
Exception in thread “main”

Well, say hello to the dreaded UnsatisfiedLinkError! This will happen if the System.loadLibrary() call failed because it couldn’t find the shared library file. As our shared library is located in the “Debug” folder we have to tell the JVM where to find it. Open the Run configuration of the JNIDemo class and add “-Djava.library.path=Debug/” as a VM argument. When we rerun the program we get this output:


Exception in thread “main” java.lang.UnsatisfiedLinkError: com.badlogic.jnidemo.JNIDemo.add(II)I
at com.badlogic.jnidemo.JNIDemo.add(Native Method)
at com.badlogic.jnidemo.JNIDemo.main(JNIDemo.java:20)

Now that is a bit strange. We again get an UnsatisfiedLinkError but this time it seems that the native method itself can’t be found in the shared library. The problem is that exporting symbols to shared libraries on Windows is kinda fucked up. To fix that we have to pass a flag to the C++ linker that generates the shared library file. For this open the properties dialog of the project and go to “C/C++Builder/Settings” again. In the right hand side of the window select “MinGW C++ Linker/Miscellanious”. Now you see an input box called “Linker Flags”. Put the string “-Wl,–kill-at” in there:

Close the dialog and click the hammer again. Everything should still compile fine. Now let’s run the JNIDemo Java program once more. Here’s the output:


5

Yes, it finally works! Now we have everything working. When you modify your C++ source files all you need to do is rebuilding the project in the C++ view. You can also let CDT automatically rebuild the C++ portion of your code in case you modified a file. I found that to be to time consuming so i don’t turn it on normally.

Now the final piece of the puzzle is debugging. There’s not a lot of information out there how to debug JNI code in Eclipse so i hope this little guide will help you. Let’s start of by placing breakpoints. The first one goes into line 20 of the JNIDemo.java file, the second one into line 11 in the JNIDemo.cpp file. Next we create a new Debug Configuration. For this we have to go to the “Debug configurations” dialog which we can find here:

In the dialog that pops up double click on “C/C++ Attach to Application”. This will create a new C++ debugger configuration that works with our shared library file named libjnidemo.dll.

Next we have to select what debugger to use. Remember how we installed MinGW gdb in the beginning? That’s what we’ll tell the configuration to use now. Click on the Debugger tab and select “MinGW gdb Debugger” from the Debugger drop down list:

Now close the dialog and start the Java class JNIDemo in debug mode. Wait for the debugger to arrive at the break point in line 20. When the debugger got there start the C++ debugger configuration you just created. A dialog will pop up that asks you to what executable to attach the debugger to. Choose “javaw.exe”. Wait for the debugger to load, then resume “Thread 1” of the jnidemo C++ debugger:

Next resume the Java debugger. And tada! The c++ debugger will break at line 11 in JNIDemo.cpp. You can even inspect the parameters. Awesome.

That’s all there is to this. Well, one thing i left out. Up until now, all the changes we did to the C++ properties of our project have been made to it’s Debug configuration. By default CDT will also create a Release configuration. If you want a release ready shared library you have to set the same things in the Release configuration too. To select which configuration is active just click the arrow beside the hammer icon. Also, if you want to make your project cross plattform you’ll have to have seperate configurations for each platform.

That’s it for now, hope that helps some people out there. For Android this approach is not working 100%. You can’t build a shared library this way (well, you can but setting it up is a bit of a pain in the ass) and you also can’t debug. But what you can do is using the features CDT offers you like code completion and so on. Just make sure you set the proper include paths for the C++ compiler in the projects properties and indexer will pick up the header files for code completion.

8 thoughts on “Mixing Java & C++ in one Eclipse project and debugging the crap out of it.

  1. I like the last paragraph: “That’s all there is to this” *ggg*

    But from experience it works out the best to separate as much as possible.

  2. The article is a bit lengthy as it explains every single step in the creation of a mixed project. That’s often left out in such guides and responsible for a lot of confusion and errors.

    I agree that seperation of concern is important. However, When i write a native library that only serves the purpose of getting something to perform better in a java library/program i like to have the C++ and Java sources close to each other.

  3. I particularly appreciate the fact that you showed the errors that occurred before taking each step to correct them, and why the steps were necessary. Most step-by-step tutorials only tell you what to do, not why you should do it or what will go wrong if you don’t.

  4. Hi,
    good article, but I have a probel after “resume” on Thread 1, all the previous steps are ok.
    I receive the error:
    “Warning:\nCannot insert breakpoint 1.\nError accessing memory address 0x62881196: Input/output error.\n”
    (gdb)”
    Can you suggest me how solve this, thanks.
    My platform is:
    – Window Vista
    – JDK 1.6
    – MinGW 1.5.6
    – gdb-7.0.50
    – eclipse 3.5

    I follow your instruction and double check it, this is my log:

    Reading symbols from C:\Users\Sandro\workspace35\TestJNI\Debug\TestJNI.dll…done.
    .gdbinit: No such file or directory.
    1-gdb-set confirm off
    1^done
    (gdb)
    2-gdb-set width 0
    2^done
    3-gdb-set height 0
    (gdb)
    3^done
    (gdb)
    4-interpreter-exec console echo
    4^done
    5-gdb-show prompt
    (gdb)
    5^done,value=”(gdb) ”
    (gdb)
    6
    &”\n”
    6^done
    (gdb)

    7-gdb-set stop-on-solib-events 0
    7^done
    8-gdb-set stop-on-solib-events 1
    (gdb)
    8^done
    9 attach 280
    (gdb)
    attach 280
    &”attach 280\n”
    =thread-group-created,id=”280″
    =thread-created,id=”1″,group-id=”280″
    ~”[New Thread 280.0x1d58]\n”
    [New Thread 280.0x1d58]
    9^running
    *running,thread-id=”all”
    (gdb)
    =thread-created,id=”2″,group-id=”280″
    ~”[New Thread 280.0×1648]\n”
    [New Thread 280.0×1648]
    *running,thread-id=”all”
    =thread-created,id=”3″,group-id=”280″
    ~”[New Thread 280.0xde8]\n”
    [New Thread 280.0xde8]
    *running,thread-id=”all”
    =thread-created,id=”4″,group-id=”280″
    ~”[New Thread 280.0x158c]\n”
    [New Thread 280.0x158c]
    *running,thread-id=”all”
    =thread-created,id=”5″,group-id=”280″
    ~”[New Thread 280.0×1830]\n”
    [New Thread 280.0×1830]
    *running,thread-id=”all”
    =thread-created,id=”6″,group-id=”280″
    ~”[New Thread 280.0x1b3c]\n”
    [New Thread 280.0x1b3c]
    *running,thread-id=”all”
    =thread-created,id=”7″,group-id=”280″
    ~”[New Thread 280.0x19a4]\n”
    [New Thread 280.0x19a4]
    *running,thread-id=”all”
    =thread-created,id=”8″,group-id=”280″
    ~”[New Thread 280.0×914]\n”
    [New Thread 280.0×914]
    *running,thread-id=”all”
    =thread-created,id=”9″,group-id=”280″
    ~”[New Thread 280.0x1e4]\n”
    [New Thread 280.0x1e4]
    *running,thread-id=”all”
    =thread-created,id=”10″,group-id=”280″
    ~”[New Thread 280.0×1988]\n”
    [New Thread 280.0×1988]
    *running,thread-id=”all”
    =thread-created,id=”11″,group-id=”280″
    ~”[New Thread 280.0x1df0]\n”
    [New Thread 280.0x1df0]
    *running,thread-id=”all”
    =thread-created,id=”12″,group-id=”280″
    ~”[New Thread 280.0x1a24]\n”
    [New Thread 280.0x1a24]
    *running,thread-id=”all”
    =thread-created,id=”13″,group-id=”280″
    ~”[New Thread 280.0×1650]\n”
    [New Thread 280.0×1650]
    *running,thread-id=”all”
    =thread-created,id=”14″,group-id=”280″
    ~”[New Thread 280.0x1de8]\n”
    [New Thread 280.0x1de8]
    *running,thread-id=”all”
    =library-loaded,id=”C:\\Windows\\system32\\ntdll.dll”,target-name=”C:\\Windows\\system32\\ntdll.dll”,host-name=”C:\\Windows\\system32\\ntdll.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\kernel32.dll”,target-name=”C:\\Windows\\system32\\kernel32.dll”,host-name=”C:\\Windows\\system32\\kernel32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\advapi32.dll”,target-name=”C:\\Windows\\system32\\advapi32.dll”,host-name=”C:\\Windows\\system32\\advapi32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\rpcrt4.dll”,target-name=”C:\\Windows\\system32\\rpcrt4.dll”,host-name=”C:\\Windows\\system32\\rpcrt4.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\user32.dll”,target-name=”C:\\Windows\\system32\\user32.dll”,host-name=”C:\\Windows\\system32\\user32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\gdi32.dll”,target-name=”C:\\Windows\\system32\\gdi32.dll”,host-name=”C:\\Windows\\system32\\gdi32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\imm32.dll”,target-name=”C:\\Windows\\system32\\imm32.dll”,host-name=”C:\\Windows\\system32\\imm32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\msctf.dll”,target-name=”C:\\Windows\\system32\\msctf.dll”,host-name=”C:\\Windows\\system32\\msctf.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\msvcrt.dll”,target-name=”C:\\Windows\\system32\\msvcrt.dll”,host-name=”C:\\Windows\\system32\\msvcrt.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\lpk.dll”,target-name=”C:\\Windows\\system32\\lpk.dll”,host-name=”C:\\Windows\\system32\\lpk.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\usp10.dll”,target-name=”C:\\Windows\\system32\\usp10.dll”,host-name=”C:\\Windows\\system32\\usp10.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\avgrsstx.dll”,target-name=”C:\\Windows\\system32\\avgrsstx.dll”,host-name=”C:\\Windows\\system32\\avgrsstx.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\msvcr71.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\msvcr71.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\msvcr71.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\client\\jvm.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\client\\jvm.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\client\\jvm.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\winmm.dll”,target-name=”C:\\Windows\\system32\\winmm.dll”,host-name=”C:\\Windows\\system32\\winmm.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\ole32.dll”,target-name=”C:\\Windows\\system32\\ole32.dll”,host-name=”C:\\Windows\\system32\\ole32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\oleaut32.dll”,target-name=”C:\\Windows\\system32\\oleaut32.dll”,host-name=”C:\\Windows\\system32\\oleaut32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\oleacc.dll”,target-name=”C:\\Windows\\system32\\oleacc.dll”,host-name=”C:\\Windows\\system32\\oleacc.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\apphelp.dll”,target-name=”C:\\Windows\\system32\\apphelp.dll”,host-name=”C:\\Windows\\system32\\apphelp.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\hpi.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\hpi.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\hpi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\psapi.dll”,target-name=”C:\\Windows\\system32\\psapi.dll”,host-name=”C:\\Windows\\system32\\psapi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\jdwp.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\jdwp.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\jdwp.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\npt.dll”,target-name=”C:\\Program F10-environment-directory C:/Users/Sandro/workspace35/TestJNI C:/Users/Sandro/workspace35/TestJNI/.settings C:/Users/Sandro/workspace35/TestJNI/Debug C:/Users/Sandro/workspace35/TestJNI/Debug/jni C:/Users/Sandro/workspace35/TestJNI/Release C:/Users/Sandro/workspace35/TestJNI/Release/jni C:/Users/Sandro/workspace35/TestJNI/bin C:/Users/Sandro/workspace35/TestJNI/jni C:/Users/Sandro/workspace35/TestJNI/src
    iles\\Java\\jdk1.6.0_10\\jre\\bin\\npt.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\npt.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\verify.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\verify.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\verify.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\java.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\java.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\java.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\zip.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\zip.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\zip.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\dt_socket.dll”,target-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\dt_socket.dll”,host-name=”C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\dt_socket.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\ws2_32.dll”,target-name=”C:\\Windows\\system32\\ws2_32.dll”,host-name=”C:\\Windows\\system32\\ws2_32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\nsi.dll”,target-name=”C:\\Windows\\system32\\nsi.dll”,host-name=”C:\\Windows\\system32\\nsi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\nlaapi.dll”,target-name=”C:\\Windows\\system32\\nlaapi.dll”,host-name=”C:\\Windows\\system32\\nlaapi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\IPHLPAPI.DLL”,target-name=”C:\\Windows\\system32\\IPHLPAPI.DLL”,host-name=”C:\\Windows\\system32\\IPHLPAPI.DLL”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\dhcpcsvc.dll”,target-name=”C:\\Windows\\system32\\dhcpcsvc.dll”,host-name=”C:\\Windows\\system32\\dhcpcsvc.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\dnsapi.dll”,target-name=”C:\\Windows\\system32\\dnsapi.dll”,host-name=”C:\\Windows\\system32\\dnsapi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\secur32.dll”,target-name=”C:\\Windows\\system32\\secur32.dll”,host-name=”C:\\Windows\\system32\\secur32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\winnsi.dll”,target-name=”C:\\Windows\\system32\\winnsi.dll”,host-name=”C:\\Windows\\system32\\winnsi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\dhcpcsvc6.dll”,target-name=”C:\\Windows\\system32\\dhcpcsvc6.dll”,host-name=”C:\\Windows\\system32\\dhcpcsvc6.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\NapiNSP.dll”,target-name=”C:\\Windows\\system32\\NapiNSP.dll”,host-name=”C:\\Windows\\system32\\NapiNSP.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\pnrpnsp.dll”,target-name=”C:\\Windows\\system32\\pnrpnsp.dll”,host-name=”C:\\Windows\\system32\\pnrpnsp.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Program Files\\Bonjour\\mdnsNSP.dll”,target-name=”C:\\Program Files\\Bonjour\\mdnsNSP.dll”,host-name=”C:\\Program Files\\Bonjour\\mdnsNSP.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\wshbth.dll”,target-name=”C:\\Windows\\system32\\wshbth.dll”,host-name=”C:\\Windows\\system32\\wshbth.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\setupapi.dll”,target-name=”C:\\Windows\\system32\\setupapi.dll”,host-name=”C:\\Windows\\system32\\setupapi.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\System32\\mswsock.dll”,target-name=”C:\\Windows\\System32\\mswsock.dll”,host-name=”C:\\Windows\\System32\\mswsock.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\System32\\winrnr.dll”,target-name=”C:\\Windows\\System32\\winrnr.dll”,host-name=”C:\\Windows\\System32\\winrnr.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\Wldap32.dll”,target-name=”C:\\Windows\\system32\\Wldap32.dll”,host-name=”C:\\Windows\\system32\\Wldap32.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\system32\\rasadhlp.dll”,target-name=”C:\\Windows\\system32\\rasadhlp.dll”,host-name=”C:\\Windows\\system32\\rasadhlp.dll”,symbols-loaded=”0″
    =library-loaded,id=”C:\\Windows\\System32\\WSHTCPIP.DLL”,target-name=”C:\\Windows\\System32\\WSHTCPIP.DLL”,host-name=”C:\\Windows\\System32\\WSHTCPIP.DLL”,symbols-loaded=”0″
    ~”[Switching to Thread 280.0x1de8]\n”
    [Switching to Thread 280.0x1de8]
    *stopped
    (gdb)
    10^done,source-path=”C:/Users/Sandro/workspace35/TestJNI;C:/Users/Sandro/workspace35/TestJNI/.settings;C:/Users/Sandro/workspace35/TestJNI/Debug;C:/Users/Sandro/workspace35/TestJNI/Debug/jni;C:/Users/Sandro/workspace35/TestJNI/Release;C:/Users/Sandro/workspace35/TestJNI/Release/jni;C:/Users/Sandro/workspace35/TestJNI/bin;C:/Users/Sandro/workspace35/TestJNI/jni;C:/Users/Sandro/workspace35/TestJNI/src;$cdir;$cwd”
    (gdb)
    11 info threads
    &”info threads\n”
    ~”* 14 Thread 280.0x1de8 0x77b48b2f in ntdll!DbgUiConvertStateChangeStructure () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 13 Thread 280.0×1650 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 12 Thread 280.0x1a24 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 11 Thread 280.0x1df0 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 10 Thread 280.0×1988 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 9 Thread 280.0x1e4 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 8 Thread 280.0×914 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 7 Thread 280.0x19a4 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 6 Thread 280.0x1b3c 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 5 Thread 280.0×1830 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 4 Thread 280.0x158c 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 3 Thread 280.0xde8 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 2 Thread 280.0×1648 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 1 Thread 280.0x1d58 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    11^done
    (gdb)
    12 info threads
    &”info threads\n”
    ~”* 14 Thread 280.0x1de8 0x77b48b2f in ntdll!DbgUiConvertStateChangeStructure () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 13 Thread 280.0×1650 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 12 Thread 280.0x1a24 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 11 Thread 280.0x1df0 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 10 Thread 280.0×1988 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 9 Thread 280.0x1e4 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 8 Thread 280.0×914 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 7 Thread 280.0x19a4 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 6 Thread 280.0x1b3c 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 5 Thread 280.0×1830 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 4 Thread 280.0x158c 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 3 Thread 280.0xde8 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 2 Thread 280.0×1648 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    ~” 1 Thread 280.0x1d58 0x77b65e74 in ntdll!LdrAccessResource () from C:\\Windows\\system32\\ntdll.dll\n”
    12^done
    (gdb)
    13-stack-info-depth
    13^done,depth=”4″
    (gdb)
    14-data-list-register-names
    14^done,register-names=[“eax”,”ecx”,”edx”,”ebx”,”esp”,”ebp”,”esi”,”edi”,”eip”,”eflags”,”cs”,”ss”,”ds”,”es”,”fs”,”gs”,”st0″,”st1″,”st2″,”st3″,”st4″,”st5″,”st6″,”st7″,”fctrl”,”fstat”,”ftag”,”fiseg”,”fioff”,”foseg”,”fooff”,”fop”,”xmm0″,”xmm1″,”xmm2″,”xmm3″,”xmm4″,”xmm5″,”xmm6″,”xmm7″,”mxcsr”,”mm0″,”mm1″,”mm2″,”mm3″,”mm4″,”mm5″,”mm6″,”mm7″]
    (gdb)
    15-stack-list-frames 0 4
    15^done,stack=[frame={level=”0″,addr=”0x77b48b2f”,func=”ntdll!DbgUiConvertStateChangeStructure”,from=”C:\\Windows\\system32\\ntdll.dll”},frame={level=”1″,addr=”0x77b8c9a0″,func=”ntdll!EtwEventEnabled”,from=”C:\\Windows\\system32\\ntdll.dll”},frame={level=”2″,addr=”0x7e06d950″,func=”??”},frame={level=”3″,addr=”0x00000000″,func=”??”}]
    (gdb)
    16-break-insert HelloWorld.cpp:10
    16^done,bkpt={number=”1″,type=”breakpoint”,disp=”keep”,enabled=”y”,addr=”0x62881196″,func=”Java_HelloWorld_print”,file=”../jni/HelloWorld.cpp”,fullname=”C:/Users/Sandro/workspace35/TestJNI/.settings/../jni/HelloWorld.cpp”,line=”10″,times=”0″,original-location=”HelloWorld.cpp:10″}
    17-stack-list-frames 0 4
    (gdb)
    17^done,stack=[frame={level=”0″,addr=”0x77b48b2f”,func=”ntdll!DbgUiConvertStateChangeStructure”,from=”C:\\Windows\\system32\\ntdll.dll”},frame={level=”1″,addr=”0x77b8c9a0″,func=”ntdll!EtwEventEnabled”,from=”C:\\Windows\\system32\\ntdll.dll”},frame={level=”2″,addr=”0x7e06d950″,func=”??”},frame={level=”3″,addr=”0x00000000″,func=”??”}]
    (gdb)
    18-data-list-changed-registers
    18^done,changed-registers=[“0″,”1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″,”10″,”11″,”12″,”13″,”14″,”15″,”16″,”17″,”18″,”19″,”20″,”21″,”22″,”23″,”24″,”25″,”26″,”27″,”28″,”29″,”30″,”31″,”32″,”33″,”34″,”35″,”36″,”37″,”38″,”39″,”40″]
    (gdb)
    19-thread-select 1
    19^done,new-thread-id=”1″,frame={level=”0″,addr=”0x77b65e74″,func=”ntdll!LdrAccessResource”,args=[],from=”C:\\Windows\\system32\\ntdll.dll”}
    (gdb)
    20-stack-info-depth
    20^done,depth=”5″
    (gdb)
    21-stack-info-depth
    21^done,depth=”5″
    (gdb)
    22-thread-select 14
    22^done,new-thread-id=”14″,frame={level=”0″,addr=”0x77b48b2f”,func=”ntdll!DbgUiConvertStateChangeStructure”,args=[],from=”C:\\Windows\\system32\\ntdll.dll”}
    (gdb)
    23-thread-select 1
    23^done,new-thread-id=”1″,frame={level=”0″,addr=”0x77b65e74″,func=”ntdll!LdrAccessResource”,args=[],from=”C:\\Windows\\system32\\ntdll.dll”}
    (gdb)
    24-stack-list-frames 0 5
    24^done,stack=[frame={level=”0″,addr=”0x77b65e74″,func=”ntdll!LdrAccessResource”,from=”C:\\Windows\\system32\\ntdll.dll”},frame={level=”1″,addr=”0x77b65620″,func=”ntdll!ZwWaitForSingleObject”,from=”C:\\Windows\\system32\\ntdll.dll”},frame={level=”2″,addr=”0x76279884″,func=”WaitForSingleObjectEx”,from=”C:\\Windows\\system32\\kernel32.dll”},frame={level=”3″,addr=”0x00000068″,func=”??”},frame={level=”4″,addr=”0x00000000″,func=”??”}]
    (gdb)
    25-thread-select 14
    25^done,new-thread-id=”14″,frame={level=”0″,addr=”0x77b48b2f”,func=”ntdll!DbgUiConvertStateChangeStructure”,args=[],from=”C:\\Windows\\system32\\ntdll.dll”}
    (gdb)
    26 info sharedlibrary
    &”info sharedlibrary\n”
    ~”From To Syms Read Shared Object Library\n”
    ~”0x77b01000 0x77c26844 Yes C:\\Windows\\system32\\ntdll.dll\n”
    ~”0x76231000 0x7630baac Yes C:\\Windows\\system32\\kernel32.dll\n”
    ~”0x763a1000 0x7646553c Yes C:\\Windows\\system32\\advapi32.dll\n”
    ~”0x767f1000 0x768b2bb4 Yes C:\\Windows\\system32\\rpcrt4.dll\n”
    ~”0x77921000 0x779bc12c Yes C:\\Windows\\system32\\user32.dll\n”
    ~”0x77d11000 0x77d5a918 Yes C:\\Windows\\system32\\gdi32.dll\n”
    ~”0x76321000 0x7633dc80 Yes C:\\Windows\\system32\\imm32.dll\n”
    ~”0x76bf1000 0x76cb7af8 Yes C:\\Windows\\system32\\msctf.dll\n”
    ~”0x76471000 0x76519234 Yes C:\\Windows\\system32\\msvcrt.dll\n”
    ~”0x77c41000 0x77c48244 Yes C:\\Windows\\system32\\lpk.dll\n”
    ~”0x761b1000 0x7622c8d4 Yes C:\\Windows\\system32\\usp10.dll\n”
    ~”0x6c1b1000 0x6c1b4048 Yes C:\\Windows\\system32\\avgrsstx.dll\n”
    ~”0x7c341000 0x7c395b64 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\msvcr71.dll\n”
    ~”0x6d8b1000 0x6db05f62 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\client\\jvm.dll\n”
    ~”0x74d21000 0x74d51174 Yes C:\\Windows\\system32\\winmm.dll\n”
    ~”0x76cc1000 0x76e04ff0 Yes C:\\Windows\\system32\\ole32.dll\n”
    ~”0x768c1000 0x7694c360 Yes C:\\Windows\\system32\\oleaut32.dll\n”
    ~”0x74c61000 0x74c9c44c Yes C:\\Windows\\system32\\oleacc.dll\n”
    ~”0x75fe1000 0x7600b84c Yes C:\\Windows\\system32\\apphelp.dll\n”
    ~”0x6d331000 0x6d3374d4 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\hpi.dll\n”
    ~”0x761a1000 0x761a61a0 Yes C:\\Windows\\system32\\psapi.dll\n”
    ~”0x6d421000 0x6d4489dc Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\jdwp.dll\n”
    ~”0x6d751000 0x6d755158 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\npt.dll\n”
    ~”0x6d861000 0x6d86b65a Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\verify.dll\n”
    ~”0x6d3d1000 0x6d3ee3a6 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\java.dll\n”
    ~”0x6d8a1000 0x6d8ae422 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\zip.dll\n”
    ~”0x6d2a1000 0x6d2a62a4 Yes C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\bin\\dt_socket.dll\n”
    ~”0x77c51000 0x77c7c818 Yes C:\\Windows\\system32\\ws2_32.dll\n”
    ~”0x76311000 0x76315058 Yes C:\\Windows\\system32\\nsi.dll\n”
    ~”0x75331000 0x7533ec10 Yes C:\\Windows\\system32\\nlaapi.dll\n”
    ~”0x75a31000 0x75a4873c Yes C:\\Windows\\system32\\IPHLPAPI.DLL\n”
    ~”0x759f1000 0x75a248a8 Yes C:\\Windows\\system32\\dhcpcsvc.dll\n”
    ~”0x75cf1000 0x75d1b220 Yes C:\\Windows\\system32\\dnsapi.dll\n”
    ~”0x76041000 0x76053aac Yes C:\\Windows\\system32\\secur32.dll\n”
    ~”0x759e1000 0x759e62a8 Yes C:\\Windows\\system32\\winnsi.dll\n”
    ~”0x759b1000 0x759d1540 Yes C:\\Windows\\system32\\dhcpcsvc6.dll\n”
    ~”0x71291000 0x7129e8e8 Yes C:\\Windows\\system32\\NapiNSP.dll\n”
    ~”0x70d81000 0x70d91d98 Yes C:\\Windows\\system32\\pnrpnsp.dll\n”
    ~”0x16081000 0x160a420a Yes C:\\Program Files\\Bonjour\\mdnsNSP.dll\n”
    ~”0x71281000 0x7128b412 Yes C:\\Windows\\system32\\wshbth.dll\n”
    ~”0x76611000 0x76799f4c Yes C:\\Windows\\system32\\setupapi.dll\n”
    ~”0x75751000 0x7578a550 Yes C:\\Windows\\System32\\mswsock.dll\n”
    ~”0x70fe1000 0x70fe72b8 Yes C:\\Windows\\System32\\winrnr.dll\n”
    ~”0x767a1000 0x767e80f8 Yes C:\\Windows\\system32\\Wldap32.dll\n”
    ~”0x720d1000 0x720d5138 Yes C:\\Windows\\system32\\rasadhlp.dll\n”
    ~”0x753f1000 0x753f4068 Yes C:\\Windows\\System32\\WSHTCPIP.DLL\n”
    26^done
    (gdb)
    27-exec-continue
    27^error,msg=”Warning:\nCannot insert breakpoint 1.\nError accessing memory address 0x62881196: Input/output error.\n”
    (gdb)
    28 kill
    &”kill\n”
    =thread-exited,id=”14″,group-id=”280″
    =thread-exited,id=”13″,group-id=”280″
    =thread-exited,id=”12″,group-id=”280″
    =thread-exited,id=”11″,group-id=”280″
    =thread-exited,id=”10″,group-id=”280″
    =thread-exited,id=”9″,group-id=”280″
    =thread-exited,id=”8″,group-id=”280″
    =thread-exited,id=”7″,group-id=”280″
    =thread-exited,id=”6″,group-id=”280″
    =thread-exited,id=”5″,group-id=”280″
    =thread-exited,id=”4″,group-id=”280″
    =thread-exited,id=”3″,group-id=”280″
    =thread-exited,id=”2″,group-id=”280″
    =thread-exited,id=”1″,group-id=”280″
    =thread-group-exited,id=”280″
    28^done
    (gdb)
    kill
    29-gdb-exit
    29^exit

  5. I solve it, my error, your procedure is perfect. I put a breakpoint on static inizializzation on java code.
    Thaks.

Leave a Reply

Your email address will not be published.