Channels ▼
RSS

.NET

Visual Studio 2008 SP1 .NET Framework Source Debugging



One feature of the Visual Studio 2008 SP1 debugger that many .NET developers are unaware of is that it can be used to debug the .NET Framework source itself. Within the Visual Studio 2008 Options dialog are settings that allow you to use a reference source server provided by Microsoft that provides access to the source code for the .NET Framework. In this article I walk you through configuring the Visual Studio 2008 SP1 debugger such that you can step into the .NET Framework itself.

Start Visual Studio 2008 SP1 and then go to the Tools menu and then select Options and locate the the General Debugging section as shown here.

Initially we will unselect the Enable Just My Code (Managed only) option which is selected by default.

Obviously we will want to select the Enable .NET Framework source stepping option.

Visual Studio 2008 SP1 needs to know where to access the framework source code and for this reason we will select the Enable source server support option.

The Visual Studio 2008 SP1 debugger needs to now know which symbols to use when debugging and so you'll want to set the Symbols settings as shown here. If you have Visual Studio 2008 SP1 installed then the Options dialog will look like the following and the two buttons at the bottom of the page are disabled.

If however you are still using the initial RTM build of Visual Studio 2008 then this Options page will be somewhat different. In that version there are two check boxes following the text box where you define the default location to save the symbol files. If you are using the RTM build and have not applied the SP1 update then leave these check boxes unselected.

When you click OK you'll receive the following warning advising you to only use symbol files that are from a known and trusted location. Click Yes to continue.

We will now define a new C# console application with which we can test the .NET Framework source debugging. Call the new project SourceDebugging or some other name of your choice.

Within the Project class we'll add a single statement calling the Console.WriteLinemethod, passing some suitable string. Press F9 on that line to create a debugger breakpoint.

We'll now press F5 to begin debugging and you'll notice the debugger begins downloading the required symbols.

Once the symbols have been successfully downloaded the debugger breaks on the breakpoint as expected.

Here is where the magic begins...

Press F11 to step into the Console.WriteLine method and you'll find that Visual Studio 2008 loads the Console.cs source file into another editor Window and breaks within the InitializeStdOutError method.

You'll notice that you have access to the source code for the Console class although you might not have expected to have access to the comments within the source too.

Until recently framework source debugging was not working on the RTM builds of Windows 7 and Windows Server 2008 R2 because the required symbols for build 7600 were not available from the public symbol servers.

If you are using either an earlier build of these operating systems then framework source debugging is unlikely to work even if you have downloaded the symbols for the build of Windows you are using. Once you have access to the RTM builds however you'll be debugging the .NET Framework source code without issue.

Have fun debugging!!!


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video