Why does generated IL code start with a Nop?

风格不统一 提交于 2019-11-27 02:08:00

问题


I was trawling through some of the IL of one of my assemblies (via ILDasm) and I noticed that all of my methods begin with a nop instruction.

Does anyone know why that is?


回答1:


The assembly was compiled in debug mode. Nop instructions do not do anything (i.e have no side effects), but act as a convenient instruction to place a breakpoint.

Tip

If you need a place for an additional breakpoint for debugging purposes, you can force the inclusion of a Nop in a Debug build by adding a pair of empty braces, e.g.

_grid.PreviewMouseRightButtonDown += (sender, e) =>
{
    _isRightMouseDown = true;

    RowColumnIndex cell = _grid.PointToCellRowColumnIndex(e);
    {} //<------ Adding a Nop allows a breakpoint here.
};


来源:https://stackoverflow.com/questions/4590382/why-does-generated-il-code-start-with-a-nop

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