I'm playing around with native code generation from C#. I'm using HeapCreate
and HeapAlloc
to allocate executable memory to which I write x86-64 instructions. I then use Marshal.GetDelegateForFunctionPointer
to turn that into a .NET delegate and call it. I am able to properly create and call a simple function that returns a constant value.
The issue is that I am unable to step into that function in VS2010. When I use "step into" in the disassembly window on the call opcode, it simply steps over and I never get to see the disassembled function. I've tried browsing to my executable memory address in the disassembly window or adding a breakpoint at that address but Visual Studio complains that the memory is not executable. I've also tried generating an "int 3" instruction but it only causes my application to exit without warning (as if Environment.Exit
was called). I've done a simple test program in C++ that uses the same technique to generate a function and call it and I can step into it without any issues.
How can I step into a native function I've generated in an allocated chunk of executable memory in a .NET Visual Studio project? Does anything prevent this from being possible? (I've got the 'just my code' option unchecked)