Version: 2023.2
Debug C# code
WinRT API in C# scripts for UWP

Debug generated C++ code

You can debug generated C++ code for your Universal Windows Platform (UWP) application using Visual Studio.

Understand class and method naming in generated C++ code

IL2CPP classes

IL2CPP classes follow the format of <ClassName>_t#number, where:

  • <ClassName> is the class name
  • The optional #number is a unique type number

Example IL2CPP classes:

IL2CPP methods

IL2CPP methods follow the format of <ClassName>_<MethodName>_m#number, where:

  • <ClassName> is the class name of the method’s declaring type
  • <MethodName> is the method name
  • #number is a unique method number

Example IL2CPP methods:

IL2CPP static field structures

Static fields structures follow the format of <ClassName>_t#number_StaticFields, where the first part of the structure name is the same as the declaring type.

Example static fields structures:

  • StringBuilder_t26_StaticFields
  • Thing_t24_StaticFields

C++ comments

Preceding each class or method definition, C++ automatically generates a comment stating the full class or method name.

Example C++ comment:

    // System.Text.StringBuilder
    struct StringBuilder_t26  : public Object_t
    {
        // System.Int32 System.Text.StringBuilder::_length
        int32_t length_1;
        // System.Int32 System.Text.StringBuilder::_maxCapacity
        int32_t maxCapacity_2;
    };

Observe variable values

You can debug your generated C++ code by observing the values of your variables using the Visual Studio debugger.

You can set breakpoints in Visual Studio where you want the debugger to stop so you can observe your variables. Visual Studio allows you to observe your variable values by either mousing over the variable or using a Watch window.

Observe a static field

In IL2CPP, Unity stores static fields in an Il2CppClass instance. To observe the values of the static field, you need to:

  1. Find the pointer to the Il2CppClass structure of that type in your code.
    Note: These pointers are in scope of the methods that use them, but after observing it once, it will remain at the same memory address during the application run.
  2. Retrieve the value of the static_fields field from that pointer. This is a pointer to a memory block containing static fields for that particular type.
  3. Cast the value to the corresponding static field structure.
  4. Observe the value in the Visual Studio debugger.

Investigate exceptions

IL2CPP uses native C++ exceptions to implement .NET exceptions.

To investigate the exceptions in your code, you can:

其他资源

Debug C# code
WinRT API in C# scripts for UWP