简体   繁体   English

从java java-> jni.dll - > app.dll - > app.dll调试dll

[英]debug a dll from java java->jni.dll ->app.dll -> app.dll

how can I debug a dll that is not loaded by the java application. 如何调试java应用程序未加载的DLL。

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应用程序正在加载正在使用另一个dll的jni.dll,而dll正在使用另一个dll。

java<->jni.dll<->dll<->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? 我在调试jni.dll时使用visual studio express但是我该怎么做才能调试其他dll?

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. 我正在使用eclipse 3.1和Visual C ++ 2003 7.1.3088(德语......抱歉;))和Windows XP。 I load some_jni.dll and some.dll in java and using the jni classes. 我在java中加载some_jni.dll和some.dll并使用jni类。 some.dll loads internaly other.dll. some.dll加载internaly other.dll。 I can debug some.dll and other.dll in visual studio. 我可以在visual studio中调试some.dll和other.dll。

Start your application and put a breakpoint to the first jni class call. 启动应用程序并在第一个jni类调用中添加断点。 Open VS and go to (in German) "Debuggen" (Debugging) -> "Prozesse" (Processes) Their you will see the javaw.exe 打开VS并转到(德语)“Debuggen”(调试) - >“Prozesse”(进程)他们你会看到javaw.exe

Select the javaw.exe and and press "Anfügen" (Attach). 选择javaw.exe,然后按“Anfügen”(附加)。

When i remeber, the code page in c++ wher the breakpoint is placed has to be open in VS. 当我记得时,c ++中的代码页必须在VS中打开断点。 VS will not open the page when the breakpoint is hit automaticaly. 当断点被自动命中时,VS将不会打开页面。 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. 加载dll并执行放置断点的代码行时,VS中的调试器将停在此位置。 Notice: this will only happen, when you compile the dll you want to debug in with debug options!!! 注意:只有在使用调试选项编译要调试的DLL时才会发生这种情况! otherwise the debugger will not stop at the C++ breakpoint. 否则调试器不会停在C ++断点处。

I did this half a year ago, but this should be the right steps. 我半年前做过这个,但这应该是正确的步骤。

It hope you get it. 希望你明白。

In visual studio you can adapt the debugger to a running java process. 在visual studio中,您可以将调试器调整为正在运行的java进程。 When a breakpoint in the C++ code is hit, the debugger will show this in visual studio and will stop the process. 当命中C ++代码中的断点时,调试器将在visual studio中显示该断点,并将停止该过程。

At the moment i have no visual studio installed but in the debug options is a window where you can see all running processes. 目前我没有安装Visual Studio,但在调试选项中是一个窗口,您可以在其中查看所有正在运行的进程。 Look for the java process and add the process to the debug session. 查找java进程并将该进程添加到调试会话中。

When the dll execute the line in which the breakpoint is placed you will see it. 当dll执行放置断点的行时,您将看到它。

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! 编辑:您必须使用调试信息编译而不是在发布模式下编译,否则视觉工作室中的debuger将不会在断点处停止!

One crude way of doing is create an infinite loop in the dll that you want to debug as: 一种粗略的做法是在要调试的dll中创建一个无限循环:

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. 一旦Java应用程序进入此循环,就通过调试器附加到此进程,并将x的值设置为0以打破循环,现在您可以逐步使用调试器。

It's been a long while since I last did this, and even then it was on Linux & Solaris. 自从我上次这样做以来已经有很长一段时间了,即便如此,它还是在Linux和Solaris上。 An incomplete solution is to embed 'hard coded breakpoints' in your DLL with " _asm int 3; " 一个不完整的解决方案是在你的DLL中使用“ _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. 每当Windows执行此指令时,它都会让桌面用户有机会将适当配置的调试器附加到受影响的进程。

It's not quite as smooth as pointing a debugger at a known process ID, but it should get you going. 它不像将调试器指向已知进程ID那样顺利,但它应该让你前进。

M. M.

As an alternative, try IKVM. 作为替代方案,请尝试IKVM。 http://www.ikvm.net/ http://www.ikvm.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM