cil

Reflection.Emit.ILGenerator Exception Handling “Leave” instruction

穿精又带淫゛_ 提交于 2019-12-23 07:48:33
问题 First, some background info: I am making a compiler for a school project. It is already working, and I'm expending a lot of effort to bug fix and/or optimize it. I've recently run into a problem with is that I discovered that the ILGenerator object generates an extra leave instruction when you call any of the following member methods: BeginCatchBlock() BeginExceptFilterBlock() BeginFaultBlock() BeginFinallyBlock() EndExceptionBlock() So, you start a try statement with a call to

Can you see the evaluation stack in mdbg?

安稳与你 提交于 2019-12-22 18:36:31
问题 Say I have the following CIL: ldc.i4 40 <- a breakpoint is set here ldc.i4.2 add box int32 call void [mscorlib]System.Console::WriteLine(string) I then use ilasm /debug main.il to assemble the exe and pdb files to use in mdbg. My question is, when I'm at say line 3, before the add operation is executed, I would want to see the evaluation stack which would show me the two int32 constants, 40 and 2, which I had loaded before. How can I view this evaluation stack in mdbg? 回答1: I found the

Debugger StepInto auto-generated code and JMC issue

做~自己de王妃 提交于 2019-12-22 12:24:04
问题 I'm making a managed .NET debugger using MDBG sample. Currently I'm struggling with StepInto behavior, while StepOut and StepOver seems to work. To achieve Just-My-Code stepping I'm calling SetJMCStatus on modules load. That works fine and allow me to debug just my code. But since I'm setting entire module as JMC, some auto-generated code comes into play and ruin stepping-into. An example of such code could be auto-property. Since debugger is executing Il instructions, with step-into I'm

Inline MSIL/CIL

二次信任 提交于 2019-12-22 08:55:07
问题 I created following simple method: public static void Main () { Console.WriteLine("Hello world!"); Console.ReadKey(true); } Then I used ILSpy to get the MSIL code: .method public hidebysig static void Main() cil managed { .entrypoint .maxstack 8 nop ldstr "Hello world!" call void [mscorlib]System.Console::WriteLine(string) nop ldc.i4.1 call valuetype [mscorlib]System.ConsoleKeyInfo [mscorlib]System.Console::ReadKey(bool) pop ret } Finally I tried to write the MSIL code into my C# code using

Inline MSIL/CIL

你说的曾经没有我的故事 提交于 2019-12-22 08:54:02
问题 I created following simple method: public static void Main () { Console.WriteLine("Hello world!"); Console.ReadKey(true); } Then I used ILSpy to get the MSIL code: .method public hidebysig static void Main() cil managed { .entrypoint .maxstack 8 nop ldstr "Hello world!" call void [mscorlib]System.Console::WriteLine(string) nop ldc.i4.1 call valuetype [mscorlib]System.ConsoleKeyInfo [mscorlib]System.Console::ReadKey(bool) pop ret } Finally I tried to write the MSIL code into my C# code using

Calling instance method on a null reference in IL

心不动则不痛 提交于 2019-12-22 05:33:47
问题 Is it correct that a instance method can be called on a null reference in IL..? Is there any example to show this..? 回答1: Yes, this is possible, as long as the method doesn't use this because the CLR does not do a null check for call instructions. You would have to modify the IL by hand as the C# compiler would almost always generate a callvirt instruction 1 . See this blog post for details and an example: Instance Methods Called on null References Sample .method private hidebysig static void

What does Array.Clear actually do under the covers?

本小妞迷上赌 提交于 2019-12-22 04:44:16
问题 I'm looking for a answer to what the Array.Clear(...) method does under the covers in C#. I've looked at the IL, but that isn't really yielding any clues, since it simply calls the System.Array::Clear(...) method in mscorlib, which then calls an unmanaged portion of the CLR that I can't observe. The reason why I am asking this, is that I am occasionally getting an SEHException thrown by my call to Array.Clear, and I can't seem to figure out why it is happening. Unfortunately, Microsoft seems

MSIL inspection

筅森魡賤 提交于 2019-12-21 19:48:11
问题 I have some MSIL in byte format (result of reflection's GetMethodBody()) that I'd like to analyze a bit. I'd like to find all classes created with the new operator in the MSIL. Any ideas on how to do that programmatically? 回答1: I ended up using the MSIL parser here: http://blogs.msdn.com/zelmalki/archive/2008/12/11/msil-parser.aspx, with the source slightly modified to work on ConstructorInfo as well as MethodInfo (results returned from reflector). It will give a list of operations, with the

c# ILGenerator nop?

丶灬走出姿态 提交于 2019-12-21 13:08:13
问题 Im generating some IL with the ILGenerator here is my code: DynamicMethod method = new DynamicMethod("test", null, Type.EmptyTypes); ILGenerator gen = method.GetILGenerator(); gen.Emit(OpCodes.Ldarg_0); gen.Emit(OpCodes.Ldarg_1); gen.Emit(OpCodes.Ldc_I4_S, 100); This generated this IL: IL_0000: ldarg.0 IL_0001: ldarg.1 IL_0002: ldc.i4.s 100 IL_0004: nop IL_0005: nop IL_0006: nop (I get the IL Code from a VS Virtulizer named ILStream) From where do the nops code? is there any way to get rid of

Is there a free tool capable of pruning unused code from a CLI assembly? [closed]

瘦欲@ 提交于 2019-12-21 12:24:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Is there a free tool capable of pruning unused code from a CLI assembly? I know there are obfuscators that are capable of performing this optimization, but these all cost money. Is there a free (or even open source) tool that removes the unused code in an already compiled assembly? 回答1: There is. It's called the