在Visual Studio中通过“成功的本地转换”?

时间:2021-12-18 22:17:48

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):

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

在Visual Studio中通过“成功的本地转换”?

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

但在进入这个电话(F11)之后,我发现自己并没有在FFF9BFD8;相反,我在GetProfilesDirectory代码中找到了正确的位置:

在Visual Studio中通过“成功的本地转换”?

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.

在堆栈上也有[成功地进行了本地转换]条目,这暗示了Visual Studio刚刚跳过了一大堆代码。

How can I step through this transition?

我怎样才能完成这个转变呢?

2 个解决方案

#1


3  

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:

我很惊讶没有人建议您在调试窗口中显示外部代码。如果您右键单击[本地管理转换]行,并在Show External Code选项中勾选,您将看到在转换过程中正在调用哪些方法。这可能会给你一个更好的主意。这是一个例子:

在Visual Studio中通过“成功的本地转换”?

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

然后,您将能够双击任何(greyed out)行,并且一个反汇编页面将使用该代码打开。另一个例子:

在Visual Studio中通过“成功的本地转换”?

#2


1  

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.

在Visual Studio中,您不能这样做,也就是说,没有办法将VS调试器转换为一个模式,以查看在成功的本地转换过程中发生了什么。

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).

你可以尝试一下WinDbg + SOS/SOSEX,因为WinDbg没有向你隐瞒这些细节。然而,这部分是。net或Windows内部抽象,所以即使您能看到它,您可能也不会得到太多,看看在那里实际发生了什么(除了程序集),您还需要mscorlib、mscoreei或clr dlls (pdb文件)的私有符号。

#1


3  

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:

我很惊讶没有人建议您在调试窗口中显示外部代码。如果您右键单击[本地管理转换]行,并在Show External Code选项中勾选,您将看到在转换过程中正在调用哪些方法。这可能会给你一个更好的主意。这是一个例子:

在Visual Studio中通过“成功的本地转换”?

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

然后,您将能够双击任何(greyed out)行,并且一个反汇编页面将使用该代码打开。另一个例子:

在Visual Studio中通过“成功的本地转换”?

#2


1  

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.

在Visual Studio中,您不能这样做,也就是说,没有办法将VS调试器转换为一个模式,以查看在成功的本地转换过程中发生了什么。

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).

你可以尝试一下WinDbg + SOS/SOSEX,因为WinDbg没有向你隐瞒这些细节。然而,这部分是。net或Windows内部抽象,所以即使您能看到它,您可能也不会得到太多,看看在那里实际发生了什么(除了程序集),您还需要mscorlib、mscoreei或clr dlls (pdb文件)的私有符号。