Hi --
I just compiled a C++ app with the CLR flag for the first time that I had previously only compiled to the native code platform. I did this so I could write debug information to the Output window, but I will want more extensive interaction with the managed environment in the future. In my app I allocate a piece of memory with VirtualAlloc with the PAGE_EXECUTE_READWRITE flag set and then proceed to generate some intel code to that memory.
I'm finding that when I compile with the CLR flag I can no longer use the debugger to view my generated code in the disassembly window, which of course prevents me from setting breakpoints or tracing through my code. When I attempt to enter the desired address in the disassembly window's Address combo list, I receive a popup message informing me that "The specified address cannot be displayed. There is no code at the supplied location." Is thhis intended behavior and is there something I can do to re-enable debugging of my generated code
Also, while I'm asking, I saw that the size of the memory footprint of my target app, as reported in Task Manager, jumped from around 2MB to around 16+MB just by compiling with the /CLR flag. Is that normal Or is there stuff I can do to reduce this footprint
Any help would be greatly appreciated, especially on the first, more urgent question.
Regards,
Mike

PAGE_EXECUTE_READWRITE and the CLR -- debugging issues
Ruud Baars
After some investigation, it appears that the window shows that error message ("The specified address cannot be displayed...") when the debugger is in a managed frame in the callstack (use the [Native to Managed Transition] and [Managed to Native Transition] thunks in the callstack window to identify what type of frame are you in).
As a workaround, move your debugger's context to a native frame (by double-clicking a native function in the callstack). Now you should be able to set the Address in the Disassembly window to any address in memory and then specify the breakpoints or tracepoints you want for that code.
-- Marian Luparu
Visual C++ IDE
ShodanTech
Hi --
Thank you so much for responding, but unfortunately that doesn't seem to have done the trick.
My settings in the Debugging options screen are as follows:
Command : $(TargetPath)
CommandArguments: (blank)
Working Directory : (blank)
Attach: No
DebuggerType: Mixed
Environment : (blank)
Merge Environment: Yes
SQL Debugging: No
Is there anything else you can think of that might be affecting this
FYI,
Here's the call that allocates the memory:
m_Image = (BYTE*)VirtualAlloc(NULL,1024*1024,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
The Intel instructions written to this memory are definitely being executed, because I see the strings that are ultimately being written to the OutputWindowPane I've added. It's just the disassembly window that won't cooperate.
Any other suggestions would be immensely appreciated. If I can't get past this it has serious implications for our ability to integrate with Visual Studio!!!
Regards,
Mike
andylongo
Hi Marian
Thank you so much, that did the trick. I am still a bit perplexed about one thing, however. My C++ program doesn't do very much except write an assembly language image to the memory it has allocated and then execute it. Thus there weren't very many calls on the call stack to choose from. I noticed that the topmost one was something called mainCRTStartup, which is reported as a C function. Then there's a thunk to my app's main function, which is now running in a managed frame. I have a single class that initializes and executes the assembly code and what is perplexing to me is that the class's constructor runs in a managed stack frame, but the call to Execute (made from within the constructor) thunks back to native code. Is the explanation something like the following: that the constructor is invoked by managed code so it runs in a managed frame, but the class itself is unmanaged, so anything done from within in runs on a native frame Is that what's happening Just curious.
Now I just have to figure out the best way to synchronize my calls into the DTE, which are made not from an addin, but from the app being executed (clearly from another thread, if the number of "server busy" messages I get is any indication). Is the best practice for this documented anywhere that you know about I was thinking that maybe I need to run a tiny addin that exposes the entry points to the DTE. Would that do it This is obviously something I can research, but if you happen to have any suggestions they would be greatly appreciated.
Thanks again for your help!
Mike
Peter Nyberg
"Is thhis intended behavior and is there something I can do to re-enable debugging of my generated code "
"jumped from around 2MB to around 16+MB just by compiling with the /CLR flag. Is that normal Or is there stuff I can do to reduce this footprint "-- Marian Luparu
Visual C++ IDE
Mike Williams
"I have a single class that initializes and executes the assembly code and what is perplexing to me is that the class's constructor runs in a managed stack frame, but the call to Execute (made from within the constructor) thunks back to native code."
"Now I just have to figure out the best way to synchronize my calls into the DTE"
-- Marian Luparu
Visual C++ IDE