Skip to content

Instantly share code, notes, and snippets.

@JoshVarty
Created May 3, 2016 18:20
Show Gist options
  • Save JoshVarty/6cfe0d7595e8a2b784d7f63601316191 to your computer and use it in GitHub Desktop.
Save JoshVarty/6cfe0d7595e8a2b784d7f63601316191 to your computer and use it in GitHub Desktop.
private static void CorProcess_OnFunctionRemapOpportunity(object sender, CorFunctionRemapOpportunityEventArgs e)
{
//A remap opportunity is where the runtime can hijack the thread IP from the old version of the code and
//put it in the new version of the code. However the runtime has no idea how the old IL relates to the new
//IL, so it needs the debugger to tell it which new IL offset in the updated IL is the semantically equivalent of
//old IL offset the IP is at right now.
Console.WriteLine("The debuggee has hit a remap opportunity at: " + e.OldFunction + ":" + e.OldILOffset);
//I have no idea what this new IL looks like either, but lets start at the beginning of the method once again
int newILOffset = e.OldILOffset;
var canSetIP = e.Thread.ActiveFrame.CanSetIP(newILOffset);
Console.WriteLine("Can set IP to: " + newILOffset + " : " + canSetIP);
e.Thread.ActiveFrame.RemapFunction(newILOffset);
Console.WriteLine("Continuing the debuggee in the updated IL at IL offset: " + newILOffset);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment