逐步完成“托管到本机的转换”在视觉工作室中?

发布于 2025-01-07 16:34:41 字数 557 浏览 2 评论 0原文

在尝试回答这个问题时,我决定需要在调试器视图中手动逐步完成编组过程。

不幸的是,Visual Studio 似乎直接跳过了所有这些有趣的代码。以下是对 GetProfilesDirectory(WinAPI 函数)的 P/Invoke 调用:

在此处输入图像描述

但是进入此调用 (F11) 后,我发现自己不在 FFF9BFD8 处;相反,我直接进入 GetProfilesDirectory 代码:

在此处输入图像描述

还有 [托管到本机转换] 堆栈上的条目,暗示 Visual Studio 刚刚跳过了一大堆代码。

我如何逐步完成这一转变?

While trying to answer this question I decided I need to step through the marshalling process by hand, in the debugger view.

Unfortunately, Visual Studio seems to jump right over all this interesting code. Here's the P/Invoke call to GetProfilesDirectory (a WinAPI function):

enter image description here

but after stepping into this call (F11), I don't find myself at FFF9BFD8; rather, I land right in the GetProfilesDirectory code:

enter image description here

There's also the [Managed to Native Transition] entry on the stack, hinting at the fact that Visual Studio had just jumped over a whole bunch of code.

How can I step through this transition?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2025-01-14 16:34:41

我很惊讶没有人建议您在调试窗口中显示外部代码。如果右键单击 [Native to Managed Transition] 行并勾选“显示外部代码”选项,您将准确地看到转换中正在调用哪些方法。这可能会给你一个更好的主意。这是一个示例:

Display Native to Managed Transition

然后,您将能够双击任何(灰色)行,并且将打开一个包含代码的反汇编页面。另一个例子:

“在此处输入图像描述"

I'm surprised that no one has suggested that you show the external code in the debug window. If you right click on the [Native to Managed Transition] line and tick the Show External Code option, you will see exactly which methods are being called in the transition. This may give you a better idea. Here is an example:

Display Native to Managed Transition

You will then be able to double click on any (greyed out) line and a Disassembly page will open with the code. Another example:

enter image description here

没有伤那来痛 2025-01-14 16:34:41

在 Visual Studio 中,您无法执行此操作,即无法将 VS 调试器切换到某种模式来查看托管到本机转换期间发生的情况。

您可以尝试 WinDbg + SOS/SOSEX,因为 WinDBG 不会向您隐藏此类详细信息。但是,该部分是 .NET 或 Windows 内部抽象,因此即使您可以看到它,您也可能不会得到太多信息,因为要查看那里实际发生的情况(除了程序集之外),您将需要 mscorlib、mscoreei 的私有符号、或 clr dll(pdb 文件)。

In Visual Studio, you cannot do that, i.e. there is no way to switch VS debugger into a mode to see what is going on during Managed to Native transition.

You could try WinDbg + SOS/SOSEX instead as WinDBG does not hide these kinds of details from you. However, that part is either .NET or Windows internal abstraction, so even if you could see it, you might not get much, as to see what's actually going on there (besides the assembly), you will need private symbols for mscorlib, mscoreei, or clr dlls (pdb files).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文