[VS2010]デバッグ時に.Net Frameworkのソースコードへステップインさせ、アセンブラのコードを表示させる

VisualStudioでWinFormを使用したプログラムを作成する場合、Form_Load()処理などのイベントハンドラを作成しハンドラ内に処理を記述していきます。
この際、Form_Load()の呼び出し元側は、.Net Frameworkのイベントループ処理となるのですが、この処理は呼び出し履歴ウィンドウで確認しても”外部コード”と表示されているだけで、どんなメソッドが呼び出されているか分かりません。




今回は、デバッグ時に”外部コード”の中身を表示させ、呼び元側にジャンプできるようにする方法を説明します。
これには、ステップインができるように、VisualStudio設定を変更させる必要があります。

.NET Frameworkソースへのステップイン設定


VisualStudioのツール->オプションを選択します。


左のメニューよりデバッグを選択し、「.NET Framework ソースのステッピングを有効にする」にチェックを入れます。


ダイアログが表示されるのでOKをクリックします。



オプションダイアログを閉じると、pdbファイルのダウンロードが行われます。
完了するまでしばらく時間が掛かります。



上記の設定を行い、フォームのLoadイベントハンドラでブレークさせてみます。



すると、呼び出し履歴のウィンドウにWinwods.Forms.FromのOnLoad()情報が表示されるようになります。


これをダブルクリックすると、新しいウィンドウが表示されます。


逆アセンブルの表示のリンクをクリックすると、コンパイル後のアセンブラが表示されます。



デバッグシンボル(pdb)ファイルをダウンロードし、キャッシュさせる

上記の設定に加え、次の作業を行っておくと.NET Frameworkライブラリ自体のpdbファイルをmicrosoftのサーバよりダウンロードし、キャッシュさせておく事が可能です。

先ほど確認した呼び出し履歴のウィンドウを右クリックし、シンボルの設定を選択します。


デバッグ->シンボルより、右側のMicrosoftシンボルサーバにチェックを入れます。
また、Windows.Forms.Formパッケージのpdbも欲しい場合は、下にある”除外されるモジュールの指定”リンクをクリックし、チェックをはずしておきます。


警告ダイアログが表示されるのでOKをクリックします。
この警告どおり、初回の実行時はpdbファイルをマイクロソフトのサーバからダウンロードするため、処理が遅くなってしまいます。(2回目以降はキャッシュが効くので問題ないです)



なお、VisualStudioの設定変更などを行いたくなく、ただソースが見たいだけの場合は下記のサイトより


なお、ネットに繋げない環境で利用したい場合は、下記のサイトより予めダウンロードしておく事も可能なようです。
http://referencesource.microsoft.com/netframework.aspx



また、このライセンスですが、以下のようになっています。

---------------
Overview
---------------
The Microsoft Reference Source License (MS-RSL) is the most restrictive of the Microsoft 
source code licenses. The license prohibits all use of source code other than the viewing 
of the code for reference purposes. The intent of this license is to enable licensors to 
release, for review purposes only, more sensitive intellectual property assets.
 
Microsoft commonly uses this license for developer libraries where modification is not 
required to make use of the source code. In these cases, the importance of transparency 
is based on the need for developers to more deeply understand the inner workings of the 
source code. In doing so, the licensees will be more effective in writing software that 
makes use of the licensed source code.
 
The copyright and patent grants in this license are both royalty free, meaning that the 
licensee does not have to pay anything to the licensor to make use of the source code. 
The license limits the source code release to use on the Windows platform only. 
Microsoft cannot provide legal advice on the use or implications of this license. 
We recommend that developers obtain appropriate legal advice before deciding
how to license their source code.
 
The source code for the .NET Framework libraries are released under a modified 
Microsoft Reference Source License.
 
---------------
Terms of Use
---------------
Developers who wish to access source code under the Reference Source Program must 
agree to the license that accompanies the code.
Licensees may use the source code to assist with the development of commercially distributed products.
Licensees may not modify or redistribute the source code.
 
 
-------------------------
Eligibility Requirements
-------------------------
There are no eligibility requirements for this program. Everyone who agrees to the 
accompanying license may use the source code provided under the Reference Source Program.


http://referencesource.microsoft.com/referencesourcelicensing.aspx より

関連記事

コメントを残す

メールアドレスが公開されることはありません。