“[Lightweight Function]” in the call stack

家住魔仙堡 提交于 2019-12-04 17:06:18

问题


I'm debugging a program (VS2008), and I was stepping through lines of code. I came across one line where a delegate function was being called, and I tried to step into it. However, rather than stepping into the method as I expected, the method was bypassed, with the debugger instead stepping into what I assume is a function called by the delegate. In the call stack, the line where I expected the delegate method to be is greyed out with the text [Lightweight Function].

What does the "Lightweight Function" part mean? Is there a way to step into this function?


回答1:


I believe a lightweight function refers to a DynamicMethod, i.e. one that is emitted at runtime, used, and then unloaded.

This blog post is related to Iron Python, but the information should be good for any .NET project: Viewing Emitted IL. The author shows you how to use a lower level debugger (windbg.exe) to see these "lightweight functions."




回答2:


Looks like this is a DynamicMethod. See this for some insight.

I'm not sure about stepping into a dynamic method, though.




回答3:


Callstack for DynamicMethod (both in Debug and Release mode):

[Lightweight Function]  
[Native to Managed Transition]  
mscorlib.dll!System.Reflection.Emit.DynamicMethod.Invoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfo culture) + 0x199 bytes

Pure

[Lightweight Function]

frame can be observed when a delegate to a dynamic method is called.



来源:https://stackoverflow.com/questions/1355968/lightweight-function-in-the-call-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!