tags:

views:

1754

answers:

6

how can I debug a dll that is not loaded by the java application.

The scenario is this: my java app is loading the jni.dll that is using another dll and that dll is using another dll.

java<->jni.dll<->dll<->dll

I have the source code for all modules

I am using visual studio express when debugging the jni.dll but what should I do to be able to debug the other dlls?

A: 

It's been a long while since I last did this, and even then it was on Linux & Solaris. An incomplete solution is to embed 'hard coded breakpoints' in your DLL with "_asm int 3;"

Whenever Windows executes this instruction it gives the desktop user the chance to attach a suitably configured debugger to the afflicted process.

It's not quite as smooth as pointing a debugger at a known process ID, but it should get you going.

M.

Martin Cowie
A: 

In visual studio you can adapt the debugger to a running java process. When a breakpoint in the C++ code is hit, the debugger will show this in visual studio and will stop the process.

At the moment i have no visual studio installed but in the debug options is a window where you can see all running processes. Look for the java process and add the process to the debug session.

When the dll execute the line in which the breakpoint is placed you will see it.

EDIT: The dll you have to compile with debug informations and not in release mode, otherwise the debuger in visual studio will not stop at the breakpoint!

Markus Lausberg
A: 

I can debug the jni dll with attach process in visual studio, but I want to be able to debug the dlls that the jni dll is communicating with.

+5  A: 

but this is the same.

I do the same, so let me explain my working set.

I am using eclipse 3.1 and Visual C++ 2003 7.1.3088 (German... sorry ;) ) and Windows XP. I load some_jni.dll and some.dll in java and using the jni classes. some.dll loads internaly other.dll. I can debug some.dll and other.dll in visual studio.

Start your application and put a breakpoint to the first jni class call. Open VS and go to (in German) "Debuggen" (Debugging) -> "Prozesse" (Processes) Their you will see the javaw.exe

Select the javaw.exe and and press "Anfügen" (Attach).

When i remeber, the code page in c++ wher the breakpoint is placed has to be open in VS. VS will not open the page when the breakpoint is hit automaticaly. When the dll is loaded and the code line where you put a breakpoint is executed, the debugger in VS will stop at this position. Notice: this will only happen, when you compile the dll you want to debug in with debug options!!! otherwise the debugger will not stop at the C++ breakpoint.

I did this half a year ago, but this should be the right steps.

It hope you get it.

Markus Lausberg
A: 

As an alternative, try IKVM. http://www.ikvm.net/

seanlinmt
A: 

One crude way of doing is create an infinite loop in the dll that you want to debug as:

int x = 1;
while(x);

Once the Java application enters this loop attach to this process through a debugger and set the value of x to 0 to break the loop and now you can step through using the debugger.

cx0der