Version: 2018.1
Universal Windows Platform: Plugins on IL2CPP Scripting Backend
FAQ (Preguntas más frecuentes)

Universal Windows Platform: Debugging on IL2CPP Scripting Backend

Aunque IL2CPP no tiene un depurador C# en este momento, es posible depurar código C++ generado utilizando Visual Studio.

Nombramiento de clases y métodos en código C++ generado

Las clases de IL2CPP se ven así: ClassName_t>#number, donde ClassName> es un nombre plano de una clase, mientras #number es un tipo de número único. #number no está presente en algunos tipos core. Por ejemplo :

String_t
Object_t
Type_t
Char_t34
StringBuilder_t26
GuidParser_t1539

Los métodos IL2CPP se ven así: ClassName>_MethodName>_m#number, where ClassName> es el nombre de la clase del tipo declarado de los métodos, MethodName> es el nombre del método y #number es el número del método. Por ejemplo:

GuidParser_ParseHex_m10003
ConfigurationSection_DoDeserializeSection_m1275
String_Format_m4102
Mathf_Sqrt_m289
Thing_Start_m1

Las estructuras de los campos estáticos se nombran así: ClassName>_t#number_StaticFields, dónde la primera parte del nombre de la estructura es idéntica al tipo declarado, por ejemplo:

StringBuilder_t26_StaticFields
Thing_t24_StaticFields

Adicionalmente, encima de cada definición de clase/método hay un comentario C++ declarando el nombre completo de la clase/método. Por ejemplo:

// System.String
struct String_t : public Object_t
{
    // System.Int32 System.String::length
    int32_t _length_0;
    // System.Char System.String::start_char
    uint16_t _start_char_1;
};

// System.Text.StringBuilder
struct StringBuilder_t26  : public Object_t
{
    // System.Int32 System.Text.StringBuilder::_length
    int32_t length_1;
    // System.String System.Text.StringBuilder::_str
    String_t* str_2;
    // System.String System.Text.StringBuilder::_cached_str
    String_t* cached_str_3;
    // System.Int32 System.Text.StringBuilder::_maxCapacity
    int32_t maxCapacity_4;
};

// System.Void MyData::.ctor()
extern "C" void MyData_ctor_m0 (MyData_t2 * this, const MethodInfo* method)
{
    ...
}

// Thing
struct Thing_t24 : public MonoBehaviour_t25
{
    // MyData Thing::m_Data
    MyData_t2 * _m_Data_2;
    // System.Text.StringBuilder Thing::m_Builder
    StringBuilder_t26 * _m_Builder_3;
};
struct Thing_t24_StaticFields
{
    // System.Int32 Thing::s_SomeStaticField
    int32_t _s_SomeStaticField_4;
};

Observando valores de variable

Una de las partes más importantes de depurar es observar los valores de varias variables. Visual Studio permite hacerlo con relativa facilidad, ya sea mousing sobre la variable de añadirlo a la ventana de reloj. Por ejemplo:

Observing static fields is a little bit harder. In IL2CPP, static fields are stored on a Il2CppClass instance itself. So in order to observe a static field, we’ll first need a pointer to Il2CppClass structure of that type. These pointers are in scope of methods that use them, but after observing it once, it will remain at the same memory address for the duration of application run. Il2CppClass structure has “static_fields” field, which is a pointer to a memory block containing static fields for that particular type. To view the actual values, this pointer has to be cast to appropriate static field structure: each type has its own. For example, let’s observe the static fields of class Thing_t24:

Investigando excepciones

IL2CPP utiliza excepciones nativas de C++ para implementar excepciones .NET. Cuando cualquier excepción se supone que es lanzada, IL2CPP lanza un objeto Il2CppExceptionWrapper, que se define como el siguiente:

struct Il2CppExceptionWrapper
{
    Il2CppException* ex;

    Il2CppExceptionWrapper (Il2CppException* ex) : ex (ex) {}
};

Estos objetos de excepción fácilmente se pueden investigar en la ventana watch:

De último, puede ser beneficioso habilitar debugger-break en la excepciones para que la fuente de la excepción se pueda atrapar. Para hacer esto, oprima CTRL+ALT+E en Visual Studio, y asegúrese de que la casilla de verificación de C++ exceptions esté marcado e la ventana abierta:

Después de habilitar esta configuración, Visual Studio automáticamente parará la ejecución cuando una excepción es lanzada:


• 2017–05–16 Page amended with no editorial review

Universal Windows Platform: Plugins on IL2CPP Scripting Backend
FAQ (Preguntas más frecuentes)
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961