[Mono-dev] Edit and Continue / Function body rewrite

David Srbecky dsrbecky at gmail.com
Sat Jul 8 05:27:37 EDT 2006


Kornél Pál wrote:
> System.Reflection.Emit is far from metadata. So you should rewrite large 
> parts of gmcs if you would like to use Cecil. 

I am definitely not going to rewrite gmcs to use Cecil. That's just too 
much work.

> I think the easiest solution is to compile using gmcs and load the output 
> using Cecil that can be used to create a low level diffgram.

Your are right. I can:
- Compile using gmcs and save the assembly to file
- Make gmcs re-emit one method to System.Reflection.Emit
- Save whole updated assembly to other file
- Load both files using cecil and make a diff

Is this possible to do with System.Reflection.Emit?  (ie Can I save 
assembly, re-emit body of one method and then save again?)


Of course I could also tell gmcs to re-emit everything to fresh assembly 
or I could just recompile everything, but I worry about performance 
here. Can anyone give me a rough estimate on how long the following 
compiling stages take relative to each other?
- lexing, parsing, semantic analysis and such
- emission of code to System.Reflection.Emit
- Saving of the assembly on disk


> But I don't know what code is actually needed to make edit and continue 
> work. (I mean the input that the runtime needs for modifying loaded 
> modules.)

I am not sure either. My guess is:
- whole IL code of the new function
- new TypeRef and MemberRef rows in metadata
- String heap

Can someone comment on that please?


David

> Kornél
> 
> ----- Original Message ----- From: "David Srbecky" <dsrbecky at gmail.com>
> To: "Kornél Pál" <kornelpal at gmail.com>
> Cc: <mono-devel-list at lists.ximian.com>
> Sent: Saturday, July 08, 2006 2:46 AM
> Subject: Re: [Mono-dev] Edit and Continue / Function body rewrite
> 
> 
> I need to compile source code and there is a great C# compiler - gmcs.
> gmcs will save the update using System.Reflection.Emit and so this is
> how I need to get the data.
> 
> Consider this:
> - I compile program using gmcs and save it to assembly Foo.exe
> - I make gmcs to reemit one method using System.Reflection.Emit
> 
> How can I now use Cecil to get the IL code of the new method? I have to
> use System.Reflection.Emit.
> 
> David
> 
> Kornél Pál wrote:
>> Cecil can read and write metadata and IL code so you can even modify 
>> existing metadata or IL code. If you want to compile source code to IL 
>> code you need a compiler. Neither System.Reflection.Emit nor Cecil 
>> provides any compiler so this is not a difference.
>>
>> Kornél
>>
>> ----- Original Message ----- From: "David Srbecky" <dsrbecky at gmail.com>
>> To: "Kornél Pál" <kornelpal at gmail.com>
>> Cc: <mono-devel-list at lists.ximian.com>
>> Sent: Saturday, July 08, 2006 2:28 AM
>> Subject: Re: [Mono-dev] Edit and Continue / Function body rewrite
>>
>>
>> I do not see how Cecil can help me - can you please outline how could I
>> use it?
>>
>> I know that Cecil can write new IL code and metadata to an assembly, but
>> that's not what I want to do - I somehow want to obtain new IL code and
>> metadata from a given source code of one method.
>>
>> David
>>
>> Kornél Pál wrote:
>>> Why do you want to extend System.Reflection.Emit when Cecil already 
>>> can do that? As far as I know Cecil can be used with .NET Framework 
>>> as well so you don't even need two different runtimes.
>>>
>>> BTW according to your previous messages you don't only want to change 
>>> IL code but you want to modify metadata and string heap as well.
>>>
>>> Kornél
>>>
>>> ----- Original Message ----- From: "David Srbecky" <dsrbecky at gmail.com>
>>> To: "Kornél Pál" <kornelpal at gmail.com>
>>> Cc: <mono-devel-list at lists.ximian.com>
>>> Sent: Saturday, July 08, 2006 1:53 AM
>>> Subject: Re: [Mono-dev] Edit and Continue / Function body rewrite
>>>
>>>
>>>>> If you want to modify existing assemblies you should use Cecil 
>>>>> (http://www.mono-project.com/Cecil) because it is designed to do 
>>>>> this while System.Reflection.Emit is designed to emit new code and 
>>>>> in fact
>>>>
>>>> I do not want to save the new IL code to assembly, I want to save it 
>>>> to memory to change a running program - but I know how to do that.
>>>>
>>>> The problem is that I need to somehow *get* the new IL code - do to 
>>>> that I need to use gmcs and System.Reflection.Emit.
>>>>
>>>>> it have less support for metadata creation than C# requires because 
>>>>> Microsoft is not using it for C# compilation so they didn't 
>>>>> reallized that System.Reflection.Emit lacks a lot of features.
>>>>
>>>> That's why I have to use Mono's System.Reflection.Emit not Mircosoft's
>>>>
>>>> David
>>>
>>
>>
> 
> 





More information about the Mono-devel-list mailing list