Unity の機能を利用して、Windows でのゲームや、エディタープロセスのフォレンジックやライブのデバッグ作業を簡単に行うことができます。
まず、デバッギングに関して説明します。Unity には 2種類のデバッギングがあります。Native C++ デバッギングと C# Managed デバッギングです。IL2CPP をサポートするプラットフォームに関しては、Native デバッギングしかありません。ただし、Managed デバッギングも、エディターの高速反復の目的で使用されます。
Native デバッギングでは、連携するバイナリ ファイル (exe か dll) にシンボル (pdb ファイル) を使用できます。
Windows では、標準 .NET が管理するシンボルが pdb ファイルに保管されています。
Unity は、シンボル ストア http://symbolserver.unity3d.com/ を提供しています。このサーバー URL は、windbg か VS2012 以降で自動シンボル解決とダウンロードに使用できます (Microsoft のシンボル ストアに類似)。
.sympath コマンドを使用すると、簡単に windbg にシンボル ストアを加えることができます。
.sympath+ SRV*c:\\symbols-cache*http://symbolserver.unity3d.com/
細かく見てみましょう。
.sympath+
プラス (+) は既存のシンボルパスを保持し、シンボルストアを追加します。
SRV*c:\symbols-cache
*http://symbolserver.unity3d.com/
フェッチ元のシンボル ストアのパスです。
注意 VS2010 以前のバージョンは http サーバーシンボルストアに使用できない場合があります。 1. Tools -> Options を選択します 2. デバッギング セクションを広げ、Symbols を選択します 3. キャッシュ ディレクトリを指定します (指定されていない場合) 4. Symbol file (.pdb) location に http://symbolserver.unity3d.com/ を入力します
Live デバッギングは、デバッガーを正常作動している処理や、発生した例外の処理に接続して行います。デバッガ―が状態を把握するために、シンボルがビルド内に含まれている必要があります。前出の手順はそのためのものです。ゲームの実行ファイル名は、ゲーム名に基づいています。そのため、もし、名前の変更をした実行ファイルにアクセスできない場合、正しい pdb を見つけられない場合があることに注意してください。
Windows では、アプリケーション キャッシュが自動的に Microsoft に報告される Dr Watson/Error Reporting が Microsoft によって設定されています。ただし、Visual Studio か windbg がインストールされている場合は、かわりに、Microsoft が精通した開発者のために提供したクラッシュのデバッギングを選択できます。 インストールを簡単にするために、こちらのレジストリ ファイルをインストールしてください。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
エディター デバッギングのちょっとしたおまけ
Unity.exe -dbgbreak
自動クラッシュ処理が設定されている場合、上記は Unity を起動して、即座にデバッガーを接続します。
Windows にはクラッシュ ダンプ ファイル (.dmp か .mdmp) を検証する機能があります。クラッシュ ダンプのタイプによって、単なるスタック情報やプロセス全体のメモリである場合もあります。内容によって、何がクラッシュの原因となったかを見るとさまざまな可能性があります。通常の場合は、少なくともスタックを検証することができます(有効なスタックである場合)。
ダンプ ファイルを検証するには、Visual Studio か windbg を通じてオプションを起動します。Visual Studio のほうが容易に使えますが、パワーに関しては、windbg よりも少し限られています。
NullReferenceException は、しばしば以下のように表示されます。
\\tmono.dll!mono_jit_runtime_invoke(_MonoMethod * method=0x242bf8b0, void * obj=0x065c3960, void ** params=0x0018cba4, MonoObject * * exc=0x0018cb8c) Line 4889 + 0xc bytes\\tC
これは、malloc のクラッシュでも mono のクラッシュでもありません。 - 以下の内、いずれかの NullReferenceException です。 * VS デバッガ―で発生した NullReferenceException * ユーザー プレイヤーでハンドルされなかったため、プレイヤーが終了する原因となった NullReferenceException
前出の例を再度見てみましょう。
\\tmono.dll!mono_jit_runtime_invoke(_MonoMethod * method=0x242bf8b0, void * obj=0x065c3960, void ** params=0x0018cba4, MonoObject * * exc=0x0018cb8c) Line 4889 + 0xc bytes\\tC
何も情報がない行は、Managed フレームです。ただし、Managed スタック情報を取得する方法があります。mono にはmono_pmip というビルトイン機能があります。これは、スタックフレームのアドレスを受領し、情報とともに char* を返します。 mono_pmip は Visual Studio のイミディエイトウィンドウで呼び出すことができます。
?(char*)mono.dll!mono_pmip((void*)0x1b45558c)
注意 mono.dll シンボルが適切に読み込まれている場合にのみ作動します。
デバッガーが接続された状態でアプリケーションがクラッシュしない場合や、デバッガーが使用できないリモートデバイスでアプリケーションがクラッシュする場合があります。 ただし、ダンプファイルを取得できる場合は、有用な情報を得ることができます。ダンプファイルを取得する手順は以下の通りです。
注 これらの手順は、Windows スタンドアロンとユニバーサル Windows プラットフォーム用 (デスクトップで実行している場合) です。
• 2017–05–16 修正されたページ
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.