How does Visual Studio’s Edit and Continue work?

Asked

Viewed 102 times

6

Visual Studio allows you to edit C#, VB.NET or C++ code in debug when you hit a breakpoint or click the break button (pause icon). The name of the tool is Edit and Continue. According to the documentation

is a productivity Feature that allows you to make changes to your source code while your program is in break mode.

This tool does not work for all editions. Changing a attribute class or property in C#, for example, you need to stop debug and compile again. See "Supported code changes (C# and Visual Basic)".

How does this run-time edition work? When I edit a code snippet, is the entire edited file project and its dependencies recompiled? Or is only the edited snippet recompiled? Exists as "recompiling" only one method?

1 answer

6


I don’t have information authoritative and I think it largely depends on the specific implementation that can change as needed.

In C# and VB.NET it is more or less easy the real code that is executed to be generated at runtime through the Jitter, then there is already a compilation in the execution even when it will not use the Edit and Continue. Of course it’s a more limited compilation, it only takes one bytecode and generates the executable code. Jitter can compile only what matters, it can even recompile something if it thinks it is necessary (as far as I know . NET does not do this, but could as optimization during execution when identifying a hot path).

I believe the recompilation of bytecode occurs only in the modified method, but this depends on the implementation.

The recompilation of the source in bytecode could occur only in this method, but has a chance to be at least in the whole file of it to check that everything is right there in that source. The .NET Compiler Platform was created to be able to compile only parts of a code, even a smaller part than a method, although this will be useful in very specific circumstances.

There is probably the insertion of metadata and even dead instructions (nop) in code generation to facilitate recompilation.

Done the recompilation the Jitter will use some strategy to replace the code, or putting in the same memory area (maybe even making a deviation), most likely, or updating the references contained in every application to the method in new address.

As you have already noted it is only possible to change imperative code (with limitations), you cannot change the data structures. But you can create new ones.

In C++ a larger infrastructure is required because it does not have a Jitter. I mean, you kind of end up having to put a Jitter in the app just to do this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.