Why doesn't LocalBuilder.SetLocalSymInfo use variable names?

I tried running the sample code that appears on the documentation page for the System.Reflection.Emit.LocalBuilder class, but it seems that calls to LocalBuilder.SetLocalSymInfo(string, int, int) do nothing, since IL Dissasembler shows this as an IL for SampleAssembly. dll:

 .method public static string Function1(int32 A_0) cil managed { // Code size 10 (0xa) .maxstack 1 .locals init (string V_0, int32 V_1) IL_0000: ldarg.0 IL_0001: stloc.1 IL_0002: ldstr "string value" IL_0007: stloc.0 IL_0008: ldloc.0 IL_0009: ret } // end of method Example::Function1 

Why aren't the variable names ( myString and myInt ) listed in Dissasembler?

Environmental Information:

  • Windows 7 64 bit
  • Visual Studio 2010 Professional SP1
  • .Net 4.0.30319 SP1
  • Target structure: .Net 4 Client profile
  • Debug Configuration (for a program using System.Reflection.Emit)

Edit: as I noticed in the comment, the SampleAssembly.pdb file is created along with the SampleAssembly.dll file.

+6
source share
3 answers

The debugging support in System.Reflection.Emit is rather poor and dodgy (and to a certain extent this applies to IKVM.Reflection, as it inherits part of the corruption from the base API of the .pdb script, which should be used since the .pdb file format is not documented).

In any case, the reason the sample does not work is because the following code is missing:

 ISymbolDocumentWriter doc = myModule.DefineDocument("sourcefile", Guid.Empty, Guid.Empty, Guid.Empty); myMethodIL.MarkSequencePoint(doc, 1, 0, 1, 0); 

The method must have at least one point in the sequence, because this is how internal data structures are related to each other.

+5
source

I suspect this is due to the fact that you are creating the module as an output DLL.

Try passing true as the second parameter to AssemblyBuilder.DefineDynamicModule

+1
source

Character names are stored in the PDB file, not in the assembly.

A tool like Reflector.NET will load the PDB file, if present, to give your disassembled code better names.

You can also verify this by debugging code in the debugger with and without a PDB file.

+1
source

Source: https://habr.com/ru/post/908284/


All Articles