Microsoft KB Archive/317221

= BUG: Incomplete call stack when you debug mixed managed and unmanaged Visual C++ code =

Article ID: 317221

Article Last Modified on 1/12/2006

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ 2005 Express Edition

-



This article was previously published under Q317221



SYMPTOMS
When you mix managed and unmanaged Visual C++ code, the Microsoft Visual Studio integrated development environment (IDE) reports incomplete call stack information.

In certain cases, the mixed managed and unmanaged stack trace may miss a stack frame of unmanaged code that is above a stack frame of managed code. In other situations, only the managed stack trace is displayed, even if there is unmanaged code above the managed code.

This may cause a problem when you debug Visual C++ applications that contain both managed and unmanaged Visual C++ code. If you step out of a managed function, the debugger may continue to run.



CAUSE
When you call unmanaged code from managed code, the .NET runtime generates stubs and calls through the stubs. During the call, .NET pushes a transition frame object onto the thread stack.

The Visual Studio debugger cannot display the complete stack trace for any frames that do not contain enough information for the debugger to proceed up the call chain.

There are many types of transitions from managed into unmanaged code; most mixed stack traces display the correct call stack information.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Open Visual Studio .NET or Visual Studio 2005, and then create a new Managed Visual C++ Console Application project.  Copy and paste the following code:
 * 1) using  
 * 2) include 

// managed void manfunc(void) {   // set a Breakpoint here System::Console::WriteLine(&quot;Inside managed function.\n&quot;); }

// unmanaged void unmanfunc(void) {   printf(&quot;Inside unmanaged function.\n&quot;); manfunc; }
 * 1) pragma unmanaged
 * 1) pragma unmanaged

// main is managed void main {   printf(&quot;Inside  managed  main function.\n&quot;); unmanfunc; }                     Set a breakpoint on the following line of code in the void manfunc(void) function : System::Console::WriteLine(&quot;Inside managed function.\n&quot;);   Compile in release configuration, and then press F5 to start the debugger. When the debugger stops in System::Console::WriteLine(&quot;Inside  managed function.\n&quot;); in the manfunc function, the Call Stack window displays the following stack trace:

man_unman.exe!manfunc man_unman.exe!main man_unman.exe!mainCRTStartup

This stack misses the call to unmanfunc. </li></ol>

Keywords: kbbug kbide kbdebug kbprb kbijw kbmanaged KB317221

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.