在反向视图中进入P / Invoke调用 [英] Stepping into a P/Invoke call in disassemby view

查看:138
本文介绍了在反向视图中进入P / Invoke调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C#代码通过P / Invoke调用非托管的第三方库函数,非托管函数有一些奇怪的副作用。我想调试它,看看它在做什么。

My C# code is calling an unmanaged third-party library function via P/Invoke, and the unmanaged function is having some strange side effects. I want to debug into it and see what it's doing.

如果我调试我的C#代码,并尝试逐步进入P / Invoke调用,它会跳过代替。没有惊喜 - 我预料到它没有这个DLL的源代码,我没有告诉我可以看到反汇编视图。

If I debug my C# code, and try to "Step Into" the P/Invoke call, it steps over instead. No surprise there -- I expected that; it doesn't have the source for this DLL, and I didn't tell it I was okay with seeing the disassembly view.

所以我将调试器切换到反汇编视图(Debug> Windows> Disassembly)。现在我看到我的JITted代码中的各个x86指令。再次尝试进入P / Invoke调用。再次,它会逐步改变 - 即使我清楚地告诉它要进入x86 CALL指令。到目前为止,Google Googling已经向我展示了一些可以影响这一点的选项,而且我已经设置了这些选项:

So I switch the debugger to disassembly view (Debug > Windows > Disassembly). Now I see the individual x86 instructions in my JITted code. Again I try to step into the P/Invoke call. Again, it steps over instead -- even though I clearly told it to Step Into an x86 CALL instruction. How hard is it to step into an x86 CALL?


  • 在工具>选项>调试>常规中,启用我的代码未被选中。

  • 在项目>属性>调试选项卡中,选中启用非托管代码调试。

没问题。 Visual Studio仍然拒绝进入。

No good. Visual Studio still refuses to step in.

我没有第三方DLL的PDB,但这并不重要。我不在乎源代码或符号信息。 (嗯,实际上他们真的很好,但是我已经知道我不会得到它们。)Visual Studio可以进行x86调试(这就是的Disassembly视图)和所有我想做的是进入x86代码。

I don't have a PDB for the third-party DLL, but that shouldn't matter. I don't care about source code or symbol information. (Well, actually they'd be really nice, but I already know I'm not going to get them.) Visual Studio can do x86 debugging (that's what the Disassembly view is for), and all I want to do is step into the x86 code.

我还需要做什么来让VS让我进入P / Invoke中的x86指令调用?

What else do I need to do to get VS to allow me to step into the x86 instructions inside a P/Invoke call?

推荐答案

这可以帮助您解决问题:
(由Graviton)

This may help you solve the problem: (by Graviton)

CallingConvention = CallingConvention.Cdecl

另外这个提到你需要分离管理的调试器,并在跨越边界时重新附加非管理。您可能需要检查混合调试器的功能,并从MSDN中进行偏好设置。

Also this mentions that you need to detach managed debugger and re-attach unmanaged when crossing the boundaries. You might need to check the capabilities of mixed debugger and it's preferences from MSDN.

最后,使用 Ed Dore'答案:


在Tools.Options对话框中,选择
调试类别,并确保
启用我的代码设置为
未选中。从项目
属性中,选择调试选项卡,
然后确保选中启用非托管
代码调试。

Under Tools.Options dialog, select the Debugging category, and make sure the "Enable Just My Code" setting is unchecked. From the Project properties, select the Debug tab, and then ensure that "Enable unmanaged code debugging" is checked.

一旦你有这些平方根,
你应该得到混合模式
调试支持工作。

Once you've got these squared away, you should get the mixed mode debugging support working.

另外,如果你使用调试。附加到
进程,请确保在附加到
进程对话框中点击
选择...按钮,并选择
托管和本机调试支持。

Also, if you use "Debug.Attach To Process" , be sure to hit the "Select..." button in the "Attach To Process" dialog, and select both Managed and Native debugging support.

这篇关于在反向视图中进入P / Invoke调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆