Version: 2023.1
언어: 한국어
Visual Studio project generation for Windows
Windows integrity control

Windows debugging

Unity provides several options for debugging on Windows for forensic or live debugging of game and Editor processes. Unity allows two types of debugging: native C++ debugging and C# managed debugging.

  • Native Debugging stores symbols in Program Database (PDB) for the associated binary files, such as exe and dll.
  • On Windows, the standard .NET managed symbols are stored in PDB files with a .pdb extension.

Symbols

You can use Unity’s Symbol Store for accessing the Unity server URL in Windows Debugger (WinDbg), or Visual Studio 2019 and later for automatic symbol resolution and downloading.

Windows Debugger (WinDbg)setup

To add a symbol store on WinDbg, use the .sympath command:

.sympath+ SRV*c:\\symbols-cache*http://symbolserver.unity3d.com/

여기에서

.sympath+ +를 추가하면 존재하는 심볼 경로를 유지한 채 심볼 스토어 룩업을 추가합니다.

SRV*c:\symbols-cache SRV는 데이터를 가져오는 외부 서버를 지정합니다. 반면 c:\symbols는 다운로드된 심볼을 임시 저장하는 로컬 경로를 지정하며, 다운로드를 실행하기 전에 필요한 심볼이 없는지 이 경로를 먼저 확인합니다.

*http://symbolserver.unity3d.com/ 데이터를 가져올 심볼 스토어 경로입니다.

Visual Studio setup

To configure Visual Studio for debugging, follow these steps: 1. Tools > Options로 이동합니다. 2. Debugging 섹션을 확장한 후 Symbols를 선택합니다. 3. 캐시 디렉토리를 지정하지 않은 경우 지정합니다. 4. Add a Symbol file (.pdb) location, such as Unity’s Symbol Store.

Live debugging

Live debugging is the scenario of attaching a debugger to a process that’s already running, or to a process where an exception has been caught. For the debugger to spot the issue, you must include the symbols in the build using the steps described in the Visual Studio setup section. In addtion, if the game executable has the same name as your game name, the debugger might have issues finding the correct .pdb file, espectially if it doesn’t have access to the renamed executable.

자동 예외 디버깅 설정

On Windows, Microsoft automatically sets up application crashes to send to Dr Watson/Error Reporting to Microsoft. However, if you have Visual Studio or WinDbg installed, Microsoft provides an option to instead opt to debug the crashes.

Follow this registry file contents to install:
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
Will launch Unity and promptly offer a debugger to connect if the automatic crash handling is set up.

Post-Mortem/Forensic debugging

Windows provides facilities to investigate crash dump files (.dmp or .mdmp). Depending on the crash dump, you might either see stack information or the entire process memory. The contents of the dump file determine the cause of the crash, which typically has at least a stack to investigate (as long as it’s a valid stack).

To investigate a dump file, you can load it up via Visual Studio or WinDbg. While Visual Studio is easy to use, WinDbg provids additional features, which makes it a preferred debugging tool.

Debugging hints and tricks

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

Managed stack frames

Managed stack frames typically resemble this:

    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

The lines without any information are managed frames. You can get the managed stack information in mono using its built-in function called mono_pmip, which accepts the address of a stack frame and returns a char* with information. You can invoke mono_pmip in the Visual Studio Immediate window for debugging.

?(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 심볼이 올바르게 로드된 경우에만 작동합니다.

애플리케이션 덤프(Dumps) 강제 생성

Ocassionally, an application doesn’t crash despite having the debugger attached, or it crashes on a remote device where the debugger isn’t available. In such cases, you can get useful information from the dump file using the following steps:

참고: 아래 과정은 데스크톱 실행 시 Windows Standalone이나 유니버설 Windows 플랫폼에 모두 적용됩니다.

  1. Open the Windows registry.
  2. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting으로 이동합니다.
  3. LocalDumps 폴더가 없으면 만듭니다.
  4. 아래의 키를 추가합니다.
    • "DumpFolder"=<FolderPath goes here> , e.g., C:\Temp
    • "DumpCount"=dword:00000010
    • "DumpType"=dword:00000002
  5. 유니버설 Windows 플랫폼이나 Windows Standalone 실행 파일을 통해 애플리케이션을 실행합니다.
  6. Reproduce the crash. The dump file is created in the folder you specified earlier. You can open the dump file with your preferred debugging tool, such as Visual Studio or WinDbg.
Visual Studio project generation for Windows
Windows integrity control
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961