|
Perhaps it replaces the NOP's with any new sets of instructions if you edit your code while debugging.
I don't really know, but it seems quite possible.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Interesting point, SK!
But the developer when debugging may insert as many instructions as possible. How many NOP instructions of IL will be generated?
regards,
George
|
|
|
|
|
I didn't mean it would replace just the NOP instruction with other instructions. Infact, thats quite difficult since a NOP is 1 byte and most other instructions are more like 3bytes+
I meant instead of the debugger having to start inserting extra instructions after the current one, or before it. It can just replace (and expand) the current instruction (which is just a NOP).
But of course, what if you remove instructions, what happens then?
I think the answer to this is way beyond me
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Thanks SK,
I agree with the basic policy you posted above. But suppose I can copy and paste a large code segment into current function, save it and continue to run. In this case, I do not think compiler will be smart enough to know in advance I will past a lot of code and will reserve a lot of NOP operations. Any comments?
regards,
George
|
|
|
|
|
Pehaps they are just there for somewhere for execution of the program to wait at, safely without fear of the current instruction changing.
If you stopped on something like push 01 and you wanted to change that to push 02 and exection had paused on that instruction, would it be able to change it? Whereas if you where stopped on a NOP then the instruction will never be changed even if everything else around it is.
I think we need some kinda expert on this one.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Thanks SK!
I think it has nothing to do with NOP. It is how the function of debugger is designed -- does it allowed to change current statement or not (not means only be able to change statement from next statement to execute). Any comments?
regards,
George
|
|
|
|
|
Here is my guess:
If the compiler inserts a few nops at the _begining_ of a method, it can then replace those nops with a call + ret to another method.
thus it can re emit the entire method with all the changes, and just make a redirect from the original method to the altered method. thus not having to worry about adding too many or removing operands in the original body.
eg (pseudo):
original:
public int Foo()
{
nop
Console.Write("hello");
return 1;
}
altered:
public int Foo()
{
return RuntimeModifiedFoo();
Console.Write("hello");
return 1;
}
public int RuntimeModifiedFoo()
{
Console.Write("hello");
Console.WriteLine ("modified method");
return 123;
}
And if you edit even more, it simply replace the first "return RuntimeModifiedFoo();" with a "return RuntimeModifiedFoo#2();"
MS introduced DynamicMethod http://msdn2.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx[^]
in .NET 2, and that was at the same time as C# got edit and continue..
My 2 cents
modified on Sunday, April 27, 2008 8:47 AM
|
|
|
|
|
Interesting and smart, Roger!
A further question, if we do not inser NOP, what are the additional efforts?
regards,
George
|
|
|
|
|
I think it might be impossible to do it w/o inserting the nop.
Lets say that we have an empty method that we want to modify.
public void Foo()
{
//empty
}
and lets pretend that it looks like this in memory:
1000000 ret //start and end of foo , we can only alter this single byte w/o overwriting the next methiod
1000001 start of next method
There would simply not be any space for us to insert the call to the modified method there, we can only alter 1 byte and if we alter more we start to overwrite some other method.
(But again, I do not know if my guess is how it works, but Id say it would be the easiest approach.)
|
|
|
|
|
Thanks Roger,
Your idea is cool. Let me know if you have found any related documents. I am interested in this topic.
regards,
George
|
|
|
|
|
In the debugger, you can also set breakpoints on lines like "{" "}". Breakpoints can be only set on instructions, so the C# compiler has to emit NOPs for those lines.
I don't know if edit-and-continue needs any additional NOPs.
|
|
|
|
|
Cool, Daniel!
Let us see if other people has experience to share why emitting NOP will facilitate edit-and-continue feature?
regards,
George
|
|
|
|
|
Daniel is correct, I verified this with reflector:
static void Main(string[] args)
{
if(true)
{
Console.Write("hello");
{
{
{
}
}
}
}
}
got emitted as:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] bool CS$4$0000)
L_0000: nop
L_0001: ldc.i4.0
L_0002: stloc.0
L_0003: nop
L_0004: ldstr "hello"
L_0009: call void [mscorlib]System.Console::Write(string)
L_000e: nop
L_000f: nop
L_0010: nop
L_0011: nop
L_0012: nop
L_0013: nop
L_0014: nop
L_0015: nop
L_0016: ret
}
with one nop for each { and }
|
|
|
|
|
Cool, Roger!
But why NOP will facilitate edit-and-continue feature?
regards,
George
|
|
|
|
|
how can I read data from Video Capture Card
please help me
thanks .
en.mahdi
|
|
|
|
|
en.Mahdi wrote: please help me
Have you tried helping yourself yet?
google[^]
there's plenty of info there that'll help you . . .
|
|
|
|
|
|
Hi, I built an windows form application..
Now I copied the whole project folder into another location and I run it from there, it runs..
But when I make changes to the code or to the form design in this new location, it dosent do so and runs the old code..
Does it link to the older location??
How do I make this new code run from my new location without making changes to my old location or the old files??
|
|
|
|
|
Hi My Friend
In the Build menu select clean solution and then select clean "Your Project name" and after run your project and enjoy.
|
|
|
|
|
Reza Shojaee wrote: In the Build menu select clean solution and then select clean "Your Project name" and after run your project and enjoy.
Thanks for your answer...
But what does this "Clean Solution" mean??
|
|
|
|
|
I removes any intermediate files and rebuilds the whole solution from scratch.
So if you make changes and they don't get compiled (so the compiler is a little confused and has missed your changes) you have to tell it to rebuild everything.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Hi ,
In my project i have some dll (which written in c).
i want to use in my c# app. most of the function i am able to call, but following list of func. i don't know how to handle. any help is appreciated.
int foo(void *Buffer,UInt32 BufferLength,byte** Image);
and other is callback from DLL TO C# APP. (I implemented, but after callback, application crash).
|
|
|
|
|
How about:
int foo(IntPtr Buffer, int BufferLength, ref IntPtr Image);
I don't know if that will work or not, but it looks alright.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Hi,
in addition to the above, if you need to pass a pointer to a managed object,
use the GCHandle class to pin the object, get its handle, pass it on, and when
done free the handle.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Good Day,
I wish to have a Console Application in my WinApp. I want to use it as a sort of a "Debug Window".
Is there an easy way to do this?
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|