Unity는 게임 및 에디터 프로세스 분석이나 라이브 디버깅 작업을 Windows에서 할 수 있도록 몇 가지 옵션을 제공합니다.
Unity에서는 두 가지 타입(네이티브 C++ 디버깅, C# 관리되는 디버깅)의 디버깅을 할 수 있습니다.
네이티브 디버깅은 exe와 dll처럼 관련된 바이너리 파일에 대한 pdb 파일에 심볼을 저장합니다.
Windows에서 일반 .NET 관리 심볼은 pdb 파일에 저장됩니다.
Unity는 http://symbolserver.unity3d.com/에 심볼 스토어를 제공합니다. Microsoft의 심볼 스토어와 마찬가지로 자동 심볼 해상도와 다운로드를 위해 Windows Debugger (WinDbg) 또는 Visual Studio 2019 이상에서 Unity 서버 URL을 사용할 수 있습니다.
WinDbg에 심볼 스토어를 추가하려면 다음과 같이 .sympath 커맨드를 사용합니다.
.sympath+ SRV*c:\\symbols-cache*http://symbolserver.unity3d.com/
여기에서
.sympath+
+를 추가하면 존재하는 심볼 경로를 유지한 채 심볼 스토어 룩업을 추가합니다.
SRV*c:\symbols-cache
SRV는 데이터를 가져오는 외부 서버를 지정합니다. 반면c:\symbols
는 다운로드된 심볼을 임시 저장하는 로컬 경로를 지정하며, 다운로드를 실행하기 전에 필요한 심볼이 없는지 이 경로를 먼저 확인합니다.
*http://symbolserver.unity3d.com/
데이터를 가져올 심볼 스토어 경로입니다.
라이브 디버깅은 정상적으로 실행 중이거나 예외 오류가 발생한 프로세스에 디버거를 부착하는 경우입니다. 디버거가 상황을 파악할 수 있도록 심볼이 빌드에 포함되어야 하며 위의 과정을 통해 이루어집니다. 또한 게임 실행 파일은 게임 이름에 따라 명명되므로, 만일 변경된 실행 파일에 디버거가 접근할 수 없으면 디버거가 올바른 pdb
파일을 검색할 때 문제가 발생할 수 있습니다.
Windows에서 Microsoft는 애플리케이션 크래시가 발생하는 경우 자동으로 Dr Watson이나 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에 비해 기능이 제한되어 있습니다.
Visual Studio를 실행할 때 Unity의 VS 코드용 UnityMixedCallstack 확장자를 사용하면 디버깅이 훨씬 더 쉬워집니다.
NullReferenceException
은 보통 다음과 같은 모습입니다.
1b45558c()
> mono-2.0-bdwgc.dll!malloc(unsigned int size=12) Line 163 + 0x5f bytes C
mono-2.0-bdwgc.dll!g_hash_table_insert_replace(_GHashTable * hash=0x065c3960, void * key=0x0018cba4, void * value=0x0018cb8c, int replace=457528232) Line 204 + 0x7 bytes C
mono-2.0-bdwgc.dll!mono_jit_runtime_invoke(_MonoMethod * method=0x242bf8b0, void * obj=0x065c3960, void ** params=0x0018cba4, MonoObject * * exc=0x0018cb8c) Line 4889 + 0xc bytes C
앞의 예제를 다시 들어보겠습니다.
1b45558c()
> mono-2.0-bdwgc.dll!malloc(unsigned int size=12) Line 163 + 0x5f bytes C
mono-2.0-bdwgc.dll!g_hash_table_insert_replace(_GHashTable * hash=0x065c3960, void * key=0x0018cba4, void * value=0x0018cb8c, int replace=457528232) Line 204 + 0x7 bytes C
mono-2.0-bdwgc.dll!mono_jit_runtime_invoke(_MonoMethod * method=0x242bf8b0, void * obj=0x065c3960, void ** params=0x0018cba4, MonoObject * * exc=0x0018cb8c) Line 4889 + 0xc bytes C
정보가 없는 행은 관리 프레임입니다. 하지만 관리 스택 정보를 얻을 방법이 있습니다. mono는 스택 프레임의 주소를 수용한 후 정보와 함께 char*를 리턴하는 mono_pmip
빌트인 함수가 있습니다. mono_pmip
를 Visual Studio에서 바로 호출하려면 아래의 행을 추가해야 합니다.
?(char*){,,mono-2.0-bdwgc.dll}mono_pmip((void*)0x1b45558c)
0x26a296c0 “ Tiles:OnPostRender () + 0x1e4 (1B4553A8 1B4555DC) [065C6BD0 - Unity Child Domain]”`
참고: 위의 코드는 mono-2.0-bdwgc.dll
심볼이 올바르게 로드된 경우에만 작동합니다.
때때로 애플리케이션이 부착된 디버거와 크래시를 유발하지 않거나, 디버거를 사용할 수 없는 원격 장치에서 애플리케이션 크래시가 발생하는 경우가 있습니다. 하지만 덤프 파일을 얻을 수 있다면 유용한 정보를 얻을 수 있습니다. 아래의 과정을 참조하십시오.
참고: 아래 과정은 데스크톱 실행 시 Windows Standalone이나 유니버설 Windows 플랫폼에 모두 적용됩니다.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting
으로 이동합니다.LocalDumps
폴더가 없으면 만듭니다."DumpFolder"=<FolderPath goes here> , e.g., C:\Temp
"DumpCount"=dword:00000010
"DumpType"=dword:00000002
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.