Debug optimized code? (with inlined methods)

F

Fuzzy

I want to experiment with the JIT compiler's optimization of code,
especially regarding inline compilation of small methods.

What I have done is set the Build options for 'Optimize Code' to TRUE
and set 'Generate debugging information' to TRUE.
I run the compiled application from Windows Explorer, crank up Visual
Studio .NET, and attach to the running application with Tools -> Debug
Processes...

Since I generated debugging information I can step through C# source
code and the disassembly. However, small methods I thought would have
been inlined by the compiler are not.

Have I erred in the process somehow and prevented inline compilation?
Is there a more appropriate way to accomplish my goal?
 
M

Miha Markic [MVP C#]

Hi Fuzzy,

I am not 100% sure on this but I think that you won't get optimized code
when you generate debugging information...
Rather, build Relase and look into IL code.
 
W

Willy Denoyette [MVP]

Inlining is performed by the JITter, but it's turned off when the VS
debugger is attached. Your only option is to use a native code debugger like
the kd. exe, windbg.exe or cdb.exe.

Willy.
 
F

Fuzzy

Willy Denoyette said:
Inlining is performed by the JITter, but it's turned off when the VS
debugger is attached. Your only option is to use a native code debugger like
the kd. exe, windbg.exe or cdb.exe.

What if I start the optimized EXE (and exercise the particular code
I'm interesting in) in order for the JITer to compile the application,
THEN attach the Visual Studio debugger?

Will the debugger attach to the already compiled (and hopefully
optimized) image ?
 
F

Fuzzy

I'm most interested in actual in-line compilation of short methods, so
I need to examine the assembly produced by the JIT compiler at
runtime. Since I'm seeing NO inline methods, I'm hoping attaching the
Visual Studio debugger to a running EXE is the culprit!
 
J

Justin Rogers

The JIT does the inlining. You won't see inlined methods at the IL level.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Fuzzy said:
I'm most interested in actual in-line compilation of short methods, so
I need to examine the assembly produced by the JIT compiler at
runtime. Since I'm seeing NO inline methods, I'm hoping attaching the
Visual Studio debugger to a running EXE is the culprit!

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Hi Fuzzy,

I am not 100% sure on this but I think that you won't get optimized code
when you generate debugging information...
Rather, build Relase and look into IL code.
 
W

Willy Denoyette [MVP]

Fuzzy said:
What if I start the optimized EXE (and exercise the particular code
I'm interesting in) in order for the JITer to compile the application,
THEN attach the Visual Studio debugger?

Will the debugger attach to the already compiled (and hopefully
optimized) image ?



Sure, but make sure CLR debugging is off and Native in On.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top