Debug generated C++ code
Understand how to use Visual Studio to debug your generated C++ code.
Read time 2 minutesLast updated 7 days ago
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 , where:
<ClassName>_t#number- is the class name
<ClassName> - The optional is a unique type number
#number
Example IL2CPP classes:
- - String class
String_t - - Object class
Object_t - - Type class
Type_t - - StringBuilder class
StringBuilder_t26
IL2CPP methods
IL2CPP methods follow the format of , where:
<ClassName>_<MethodName>_m#number- is the class name of the method’s declaring type
<ClassName> - is the method name
<MethodName> - is a unique method number
#number
Example IL2CPP methods:
- - DeserializationSection method of the ConfigurationSection class
ConfigurationSection_DoDeserializeSection_m1275 - - Format method of the String class
String_Format_m4102 - - Sqrt method of the Mathf class
Mathf_Sqrt_m289
IL2CPP static field structures
Static fields structures follow the format of , where the first part of the structure name is the same as the declaring type.
<ClassName>_t#number_StaticFieldsExample static fields structures:
StringBuilder_t26_StaticFieldsThing_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:
-
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.
-
Retrieve the value of thefield from that pointer. This is a pointer to a memory block containing static fields for that particular type.
static_fields -
Cast the value to the corresponding static field structure.
-
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:
- Inspect the exception objects in the watch window
- Enable the debugger to break on C++ exceptions