Stack Trace

  • Thread starter Thread starter Sankar Nemani
  • Start date Start date
S

Sankar Nemani

Hi All,
When I create a new StackTrace object using
System.Diagnostics.StackTrace class, it does not seem to
have the complete stacktrace of the calls as it is in the
source code. We suspect it is due to optimizations. But
even the il code contains calls to all functions matching
the source code. So it must be optimizations made at
runtime. If it is true that due to optimizations, the
stack will be different, how do we choose to not do the
runtime optimizations? And more importantly why does
windows forms code does not do any optimizations and
contains full stack as in source code?
TIA
Sankar Nemani
 
Hi Sankar,

Thanks for choosing Microsoft MSDN newsgroup.

Based on my understanding, you used System.Diagnostics.StackTrace class in
your application. And found that it did not have the complete stacktrace of
the calls as in source code. So you would like to know if there is a way to
turn off the optimizations.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Before we go further, could you send me a repro sample(just remove online
from my email address) and point out which call in your source code is not
shown in stacktrace?Thanks!

Best regards,
Rhett Gong[MS]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
[Posted and mailed]

Rhett Gong said:
Thanks for choosing Microsoft MSDN newsgroup.

Based on my understanding, you used System.Diagnostics.StackTrace class in
your application. And found that it did not have the complete stacktrace of
the calls as in source code. So you would like to know if there is a way to
turn off the optimizations.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Before we go further, could you send me a repro sample(just remove online
from my email address) and point out which call in your source code is not
shown in stacktrace?Thanks!

Not that I'm the OP, but that's pretty easy to do:

using System;
using System.Diagnostics;

class Test
{
static StackTrace GetTrace()
{
return new StackTrace();
}

static StackTrace Intermediate()
{
return GetTrace();
}

static void Main(string[] args)
{
Console.WriteLine (Intermediate());
}
}

Compiling and running the above gives:

at Test.Main(String[])

To show that this is due to inlining, just insert some conditional code
in GetTrace, eg changing it to:

static StackTrace GetTrace()
{
if (DateTime.Now.Ticks==0)
return null;
return new StackTrace();
}

then you get a stack trace of:

at Test.GetTrace()
at Test.Main(String[])

because Intermediate is still inlined, but GetTrace isn't.
 
Hi,
You would like to change the behavior of the JIT-compiler so that the
machine code it generates is easier to debug.

I believe that the System.Diagnostics.DebuggableAttribute controls the
settings for an assembly. DebuggableAttribute includes two fields that
record the settings for whether the JIT compiler should optimize, and/or
generate tracking info.
Please go here for more information about
System.Diagnostics.DebuggableAttribute:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdiagnosticsdebuggableattributeclasstopic.asp

For a retail build, compilers do not set any DebuggableAttribute. The
JIT-compiler default behavior is to generate the highest performance,
hardest to debug machine code. Enabling JIT tracking lowers performance a
little, and disabling optimization lowers performance a lot.

If there is anything unclear, please feel free to let me know.

Rhett Gong[MS]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Back
Top