gpt4 book ai didi

visual-studio - 在反汇编 View 中进入 P/Invoke 调用

转载 作者:行者123 更新时间:2023-12-04 02:20:07 24 4
gpt4 key购买 nike

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

如果我调试我的 C# 代码,并尝试“步入”P/Invoke 调用,它会转而跳过。毫不奇怪——我预料到了;它没有这个 DLL 的源代码,我也没有告诉它我可以看到反汇编 View 。

所以我将调试器切换到反汇编 View (调试 > Windows > 反汇编)。现在我在 JITted 代码中看到了单独的 x86 指令。我再次尝试进入 P/Invoke 调用。再一次,它转而跳过——即使我明确告诉它进入 x86 CALL 指令。进入 x86 CALL 有多难?

到目前为止,我的谷歌搜索向我展示了几个可能影响这一点的选项,我已经设置了它们:

  • 在工具 > 选项 > 调试 > 常规中,未选中“仅启用我的代码”。
  • 在“项目”>“属性”>“调试”选项卡中,选中“启用非托管代码调试”。

  • 不好。 Visual Studio 仍然拒绝介入。

    我没有第三方 DLL 的 PDB,但这无关紧要。我不关心源代码或符号信息。 (嗯,实际上它们会非常好,但我已经知道我不会得到它们。)Visual Studio 可以进行 x86 调试(这就是反汇编 View 的用途),我想做的就是进入x86 代码。

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

    最佳答案

    This可以帮助您解决问题:
    (由引​​力子提供)

    CallingConvention = CallingConvention.Cdecl

    还有 this提到您需要在跨越边界时分离托管调试器并重新附加非托管。您可能需要检查混合调试器的功能及其来自 MSDN 的首选项。

    最后,使用 Ed Dore'回答:

    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.

    关于visual-studio - 在反汇编 View 中进入 P/Invoke 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1557406/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com