Tracing ing Visual Studio to debug. NET Framework source code

Source: Internet
Author: User
Tags mscorlib
It's finally here-the launch of the. NET reference source project. This post (hopefully !) Contains everything you need to know. over the past few weeks, we ran a pilot of this feature and collected lots of great data that helped us work through some issues and understand where people were likely to have problems.

First, though, if you have any problems, please make sure you 've followed all of the steps exactly as described. if you're still having problems, please check the FAQ/troubleshooting section at the bottom. if that doesn't work, post a comment below and I'll look into it.

Basic setup

Note this functionality isNotAvailable on the express versions of the Visual Studio 2008 products.

1) install the Visual Studio 2008 QFE. This hotfix just updates a DLL that's part of the Visual Studio debugger that fetches the source files, more details on the download page.

Update:If you get an error installing the Hotfix, try inserting your vs 2008 DVD and then running the hotfix EXE again. we're re looking into the root cause-it's related to having a prior version of vs 2008 (e.g. beta 2) installed on the machine. but this workaround shocould allow the hotfix to install properly.

2) Start Visual Studio 2008 and bring up tools> Options> debugging> General. If you are running underVisual Basic Profile, You will need to check the box onLower left of the Options DialogMarked"Show all settings"Before continuing (other profiles won't have this option ).

Set the following two settings:

    • TurnOffThe"Enable just my code"Setting
    • TurnOnThe"Enable source server support"Setting

Your settings shoshould be as below:

3) Next, bring up the "symbols" Page and set the symbols download URL and a cache location. Specifically, set the three settings below:

      • Set the symbol file location to be:Http://referencesource.microsoft.com/symbols
      • Set a cache location. make sure this is a location that your account has read/write access. a good option for this is to place this path somewhere under your user hive (e.g. c: \ Users \ javaske \ symbols)
      • Enable the "search the above locations only when symbols are loaded manually" option.

When you're finished, the settings shoshould look like the image below:

Setup is done! That's it, really!

Debugging into framework Source

For this simple example, we'll start with a blank C # windows application project, but it will work the same with a VB, web, or WPF project. to walk through this, go ahead and create that project.

Set a breakpoint inForm_load:

Now run your project to hit that breakpoint and go to yourCall StackWindow (CTRL + ALT + c). In the call stack, right click a frame that startsSystem. Windows. Forms. dll, And choose"Load symbols". This will load the symbols for the system. windows. forms assembly, which are about 10 megabytes, so the speed of the download will vary according to your connection speed. note that Visual Studio may be unresponsive during this time. however, this download is a one-time cost for each assembly. the symbols (PDB) file will be cached on your machine, in the directory specified in the steps above.

This will load the symbols for the DLL from the server, and you'll see some information in the status bar to reflect this. note that when this completes, the call frames will turn black and line numbers will be available. note you'll need to doRight click-> load symbolsStep each time you launch a debugging session (but, again, the symbols will now be cached locally so they won't have to download ). for more information on this, see the Advanced Users section below.

You have now loaded the symbols for the Windows Forms DLL and can begin viewing the code. You can view code in any way that you normally wocould in a debugging session. In this case you can eitherStep inTo the line of code above, or you canDouble-click one of the framesIn the call Stack window. For this case, we'll step in (F11).

The first time you step into code, we'll be presented with the EULA for accessing the source code. please take the time to read this EULA. if you agree to the terms of the EULA, hit accept, and the source will then be downloaded.

That's it! You're now debugging. NET Framework source!

Now, for each assembly that you 'd like to debug into just repeat the steps abve (note you'll only see the EULAOnce, Not for each file ).

There are times when the Assembly you 'd like to debug into isn't on the call stack, for example in the code below:

Before you step inGraphics. drawrectangle, You need to get the symbolsSystem. Drawing. dllLoaded. To do this, we useModules window(CTRL + ALT + u). This lists all of the modules (DLLs) loaded by the debuggee. Just findSystem. Drawing. dllIn this list,Right click, And chooseLoad symbols.

Note that once a symbol file is loaded, the path to the symbol file shows up in the "symbol file" column.

You can now step into the graphics. drawrectangle code above using F11! In this case, note, you'll have to step through the painteventargs. Graphics property code first.

Advanced Users

normally, each time you launch a debugging session, Visual Studio attempt to download symbols for each DLL that loads into the debuggee process. as part of this process, it asks each path specified in the debugging symbols Dialog for the corresponding PDB. some projects load a lot of DLLs which won't have symbols available, so this process can significantly impact debugger startup time as this probing occurs. it is mainly for this reason we 've recommended manual symbol loading in the steps abve; we don't want using this feature to degrade the debugging experience guest SS-the-board.

There is, however, a way to allow automatic symbol loading (which avoids the "load symbols" step) in a way that minimizes performance impact. this is for more advanced users because it requires regular trips back to this debugging symbols dialog. note you can quickly get to this dialog by choosing"Symbol settings..."Item on the right click menus pictured in steps abve form the call stack or modules windows.

The key is to get all of the symbols for a given project type downloaded and cached locally, then turn off the automatic symbol downloads. This will prevent the pings at debugger startup as well.

To do this, configure your setup as abve with the following difference:Uncheck"Search from the above locations ..."Item on the dialog.

Now, launch your project in the debugger. this will cause all of the symbols available for the DLLs in your process to be downloaded at on-demand as the DLLs are loaded into the process. depending on your connection speed, this cocould take a while (it's generally about 50 MB of symbols ), so it's a good idea to hit F5 then go do something else for a while. again, these symbols are cached so this is a one-time cost. visual Studio will likely be unresponsive during this download process.

Once that process has completed, stop the debugger, and uncheck the reference source server symbol location, and hit OK:

Now when you launch the debugger, symbols will load automatically and you'll be able to step in and through call stacks normally. note if you switch to a different project type (that has different assemblies), or have assemblies that are loaded later by your project, you can just repeat these steps to get any assemblies you don't have cached locally ).

FAQ/troubleshooting1) which assemblies are currently available for symbol/source loading:
    • Mscorlib. dll
    • System. dll
    • System. Data. dll
    • System. Drawing. dll
    • System. Web. dll
    • System. Web. Extensions. dll
    • System. Windows. Forms. dll
    • System. xml. dll
    • WPF (uiautomation *. DLL, system. windows. DLL, system. printing. DLL, system. speech. DLL, windowsbase. DLL, windowsformsintegration. DLL, presentation *. DLL, some others)
    • Microsoft. VisualBasic. dll
2) When I choose "load symbols" I get an open file dialog asking for the PDB.

This can be caused by one of four situations:

    • You didn't configure the symbol location URL properly from basic setup above. Ensure it'sHttp://referencesource.microsoft.com/symbols.
    • You chose a cache symbols directory that your user account doesn't have write permissions.
    • You attempted to load symbols for a DLL that's not available in the list above
    • You have a different version of. net Framework on your machine-this can happen, for example, if you're running a Windows Server 2008 beta. to check this, go to the modules window in Visual Studio (CTRL + ALT + U) and ensure that the version number of your mscorlib. DLL is 2.0.50727.1433, as below. if not, make sure you install the RTM version of. net Framework 3.5.

    • Check your "C: \ Program Files \ Microsoft Visual Studio 9.0 \ common7 \ ide" (or wherever you installed vs) for a file calledSymsrv. No. If that file exists, rename itSymsrv. Yes, And restart Visual Studio.
3) when I try to open or step into a source code file, I get a dialog that says "source is not available for this location" or I get an open file dialog for the file.

First, see FAQ Item (2) abve to ensure the symbols for the DLL were loaded successfully. You can verify this by looking in the modules window under the "symbols status" column.

If the symbols status is "symbols loaded.", check the following.

    • If you have configured Microsoft symbol server in the past, you may have already downloaded symbols for this dll that don't contain source information. try specifying a different cache path or deleting your existing cache path, and then repeating the load symbols command. see FAQ #4 For more information on this.
    • Ensure you have checked"Enable source server"Item onTools-> options-> debugging-> GeneralPage
    • Ensure that your account has read/write access to your cache path
4) I also use Microsoft symbol server to download symbols. What's the difference? Can these two programs co-exist?

Microsoft symbol server provides symbols without any source information in them. that information has been removed (sometimes referred to as "stripped") before publishing. the symbols provided on the reference source server are full symbols with debugging information.

The key to using both is to have your reference source path above the symbol server path so that those symbols are searched/found first. as described in the Advanced Users section above, you'll likely want to launch your debugger once with this configuration to get all the symbols downloaded, then uncheck both of these paths to avoid debugging launch slowdowns in the future. also note that this may conflict in the future as more DLLs are added to the reference source project. meaning, if you 've already downloaded the symbol server symbol, you'll need to delete that or change your cache path to get the reference source one (Visual Studio has no way of knowing which is which ).

One final note here, if you have the Microsoft symbol server configured via _ nt_symbol_path, you'll need to add the reference source path above to that path as well-_ nt_symbol_path overrides the above settings.

5) Does this work with 64-bit?

Yes, we 've also provided 64-bit versions of the PDBs. note some DLLs work on multiple ubuntures, so not all of them need a separate 64-bit PDB.

6) How do I set breakpoints in framework code?

Visual Studio requires the code to exactly match what is expected by the PDB. the source publishing process, however, makes some small updates to the Code, such as pushing a standard copyright banner to the end of the source file. this changes the signature (CRC) of the code file. however, it's still easy to set a breakpoint.

Just set your breakpoint as normal (you'll see it fails with a little warning icon), then right click the breakpoint and choose "location ..."

Then check the "allow source to be different" box, hit OK.

Now the breakpoint will set successfully.

If you find yourself doing this often, you can also disable source matching in general by disabling tools-> options-> debugging: "require source files to exactly match the original version ."

7) Why don't some features like "go to definition" work?

Browse database information is separate from symbol (PDB) information within the debugger, so that information is maintained by the project system when a project is compiled and is not present within the symbol files. so, unfortunately, that ability is not available here.

8) Why are some member or local variables unavailable? Why can't I step into certain functions or lines of code?

The. net Framework bits that you have installed on your machine are "retail" bits, which means they are optimized for size and performance. part of this optimization process removes certain information from the process when it is no longer needed. debugging retail assemblies reflects this. however, most debugging information is still present in the session, and setting breakpoints earlier in a function often allows it to be visible. another aspect of retail builds is that some small methods may be "inlined" which means you will not be able to step into them or set breakpoints in them. but for the most part you can step and debug as normal.

9) Why does it take so long to download some source files?

Some source files are very large-nearly 1 MB-and unfortunately limit of these are the common ones to download. however, most are significantly smaller and download quickly. source files must be downloaded each time you restart Visual Studio. they are not persistently cached like symbols are.

10) Can I just download all of the code at once?

Not currently, but we are currently working on enabling this functionality in the future.

11) When I debug into VB code, for example in Microsoft. VisualBasic. dll, there is a C # style comment at the bottom, is this a bug?

Not really-we do run a post processing step when publishing the code and it adds a standard copyright banner at the bottom. the processor, at this time, isn' t able to support multiple comment formats. having it in a non-VB format doesn't affect the debugging functionality in any way.

12) I got to a source file and all that downloaded was a blank file?

This is something we 've seen intermittently but have not been able to diagnose. if you see this, usually the workaround is to just restart vs, which will force the file to reload. if you observe this behavior, please use the "email" link on the left to email me the name of the file that failed and about what time the failure occurred.

13) what happens if I download a hotfix or a service pack? Will I be able to get source for that?

We 've built a system that allows us to publish any number of versions of source and symbols for a given product. we haven'tmade any firm decisions on how often we'll publish source and are open to customer feedback on those issues. for example, it's clear that publishing source for each service pack makes sense, but it's unclear if we'll be able to do so for each hotfix. again, we're looking forward to feedback here.

In the meantime, also note that symbol files may no longer match a module if a framework dll has been updated via a hotfix. in those cases, the modules window will indicate that the symbols cocould not be downloaded for that module. assuming a new symbol file was published, it can be downloaded and cached using "load symbols ".

14) Can I point a web browser at the symbols URL and download the symbols directly?

No, you'll getHTTP 400 (Bad request)Response.

Support

If you have any other questions, please visit our new msdn forum on the topic: reference source server discussion.

Thanks!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.