Debugging C code in a dll

When I create a program that uses JNI, I sometimes wish that it were possible to step through the C/C++ code using a symbolic debugger.

I'm using Visual C++.

Is it possible to arrange things so that when my Java code starts executing the native code contained in a .dll file that the Visual Studio debugger will kick in and allow me to step through the C code line by line?

Thanks!

[407 byte] By [caffeinea] at [2007-11-26 12:19:29]
# 1

One way is to simply put the following line at the first line of your JNI function:DebugBreak();

When the execution hit this line it should pop you a message box asking to debug your code (you'll have to choose Cancel to debug).

Then Visual Studio should open ready to debug (after some more clicks).

Regards

jfbrierea at 2007-7-7 15:08:00 > top of Java-index,Archived Forums,Socket Programming...
# 2

I know one option (but exists another, I did not use it):

1.Start your JNI module in MS Visual Studio with java.exe and add to java.exe parameter

-Xrunjdwp:transport=dt_socket,server=y,address=<DEFINE SOCKET NUMBER HERE>,suspend=n

2.From Java IDE attach Debugger to this Socket Number.

By default some Java IDEs use Socket: 8888 (see Debugger properties)

vitallisa at 2007-7-7 15:08:00 > top of Java-index,Archived Forums,Socket Programming...
# 3

If you are using the VC++ IDE, then there is a way to do it:

Open your dll project in the IDE. Go to the Project dialog, and look around for a user entry for "executable to run". Set this to java.exe, and then define appropriate java command-line parameters so that java executes your java program.

This is probably equivalent to one of the earlier posts, which seemed to do the same thing by customizing the command line.

bschauwejavaa at 2007-7-7 15:08:00 > top of Java-index,Archived Forums,Socket Programming...
# 4

I have been doing this for 5 years with MS Visual Studio 6.0/7.1/8.0, Netbeans and Eclipse.

For example,

in MS Visual Studio 6.0:

- open JNI module project;

- open settings;

- press "Debug" Tab;

- in the field "Executable for debugging session" type the full path to java.exe

- set working directory if needed;

- in "Program arguments" type:-Xrunjdwp:transport=dt_socket,server=y,address=<DEFINE SOCKET NUMBER HERE>,suspend=n -classpath<your classpaths> <java module to start>

- start C/C++ Debugger, your Java application will run;

- in Java IDE set Java Debugger to the socket selected in MS VC IDE and attach it to your Java application started from MS VC Debugger.

vitallisa at 2007-7-7 15:08:00 > top of Java-index,Archived Forums,Socket Programming...
# 5
I think this will be userful. Could u explain in more detail of the last step? say, in Eclipse, How to set the Java Debugger to the socket and attache it to the java application?thank you very much.
LiuWudonga at 2007-7-7 15:08:00 > top of Java-index,Archived Forums,Socket Programming...
# 6

Set breakpoints in MS Visual Studio and in Java code. Start your Java application from MS Visual Studio. In Eclise:

- select your project node,

- open Debug settings,

- select the node "Remote Java Application",

- on Right Mouse Click open Menu and click "New",

- in "Connection Properties" type "localhost" and the socket number you use,

- press "Debug" Button.

Eclipse will attach Java debugger to MS Visual Studio Process.

vitallisa at 2007-7-7 15:08:00 > top of Java-index,Archived Forums,Socket Programming...