From 0a730c819a6c09ce6d807575f8d2c90195449f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Thu, 27 Sep 2018 19:58:18 +0300 Subject: [PATCH 01/23] Fix html5 build by adding forward declares to referenced APIs --- mono/metadata/il2cpp-compat-metadata.h | 1 + mono/metadata/mono-hash.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/mono/metadata/il2cpp-compat-metadata.h b/mono/metadata/il2cpp-compat-metadata.h index 62d1500e5d3b..14ef95b07d8b 100644 --- a/mono/metadata/il2cpp-compat-metadata.h +++ b/mono/metadata/il2cpp-compat-metadata.h @@ -25,6 +25,7 @@ SgenDescriptor il2cpp_mono_gc_make_root_descr_all_refs(int numbits); MonoGCDescriptor il2cpp_mono_gc_make_vector_descr (void); void* il2cpp_mono_gc_alloc_fixed (size_t size, void* descr, MonoGCRootSource source, void *key, const char *msg); gboolean il2cpp_mono_gc_is_moving(); +void il2cpp_mono_gc_deregister_root(char* addr); typedef void* (*MonoGCLockedCallbackFunc) (void *data); void* il2cpp_mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data); diff --git a/mono/metadata/mono-hash.c b/mono/metadata/mono-hash.c index bf099f653497..73d623d573e7 100644 --- a/mono/metadata/mono-hash.c +++ b/mono/metadata/mono-hash.c @@ -37,6 +37,8 @@ #include #include +void il2cpp_mono_gc_wbarrier_generic_store (void* ptr, MonoObject* value); + gint32 mono_g_hash_table_max_chain_length; struct _MonoGHashTable { From fce71925003054abe5b1338807e5533e2be085a1 Mon Sep 17 00:00:00 2001 From: Jonas Echterhoff Date: Tue, 16 Oct 2018 12:03:33 +0200 Subject: [PATCH 02/23] Use mono_gc_wbarrier_set_field instead of il2cpp_gc_wbarrier_set_field, so we can use barriers on both mono and il2cpp --- mono/mini/debugger-agent.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 1b42c452463e..941fb74cfc76 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -4178,11 +4178,9 @@ thread_startup (MonoProfiler *prof, uintptr_t tid) tls = g_new0 (DebuggerTlsData, 1); #endif MONO_GC_REGISTER_ROOT_SINGLE (tls->thread, MONO_ROOT_SOURCE_DEBUGGER, NULL, "Debugger Thread Reference"); + mono_gc_wbarrier_set_field(tls, (void**)&tls->thread, thread); #ifdef RUNTIME_IL2CPP - il2cpp_gc_wbarrier_set_field(tls, (void**)&tls->thread, thread); tls->il2cpp_context = il2cpp_debugger_get_thread_context (); -#else - tls->thread = thread; #endif mono_native_tls_set_value (debugger_tls_id, tls); @@ -4220,11 +4218,7 @@ thread_end (MonoProfiler *prof, uintptr_t tid) #ifndef RUNTIME_IL2CPP MONO_GC_UNREGISTER_ROOT (tls->thread); #endif -#ifdef RUNTIME_IL2CPP - il2cpp_gc_wbarrier_set_field(tls, (void**)&tls->thread, NULL); -#else - tls->thread = NULL; -#endif + mono_gc_wbarrier_set_field(tls, (void**)&tls->thread, NULL); } } mono_loader_unlock (); @@ -7736,11 +7730,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr, g_free (vtype_buf); return err; } -#ifdef RUNTIME_IL2CPP - il2cpp_gc_wbarrier_set_field(NULL, (void**)addr, mono_value_box_checked (d, klass, vtype_buf, &error)); -#else - *(MonoObject**)addr = mono_value_box_checked (d, klass, vtype_buf, &error); -#endif + mono_gc_wbarrier_set_field(NULL, (void**)addr, mono_value_box_checked (d, klass, vtype_buf, &error)); mono_error_cleanup (&error); g_free (vtype_buf); } else { From f0fcf2eb4b84d16284242e69d18c5ab6cd52900b Mon Sep 17 00:00:00 2001 From: Jonas Echterhoff Date: Wed, 17 Oct 2018 11:29:55 +0200 Subject: [PATCH 03/23] Use mono_gc_wbarrier_generic_store instead of mono_gc_wbarrier_set_field --- mono/mini/debugger-agent.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 941fb74cfc76..ca42dc5cdf08 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -4178,7 +4178,7 @@ thread_startup (MonoProfiler *prof, uintptr_t tid) tls = g_new0 (DebuggerTlsData, 1); #endif MONO_GC_REGISTER_ROOT_SINGLE (tls->thread, MONO_ROOT_SOURCE_DEBUGGER, NULL, "Debugger Thread Reference"); - mono_gc_wbarrier_set_field(tls, (void**)&tls->thread, thread); + mono_gc_wbarrier_generic_store((void**)&tls->thread, thread); #ifdef RUNTIME_IL2CPP tls->il2cpp_context = il2cpp_debugger_get_thread_context (); #endif @@ -4218,7 +4218,7 @@ thread_end (MonoProfiler *prof, uintptr_t tid) #ifndef RUNTIME_IL2CPP MONO_GC_UNREGISTER_ROOT (tls->thread); #endif - mono_gc_wbarrier_set_field(tls, (void**)&tls->thread, NULL); + mono_gc_wbarrier_generic_store((void**)&tls->thread, NULL); } } mono_loader_unlock (); @@ -7730,7 +7730,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr, g_free (vtype_buf); return err; } - mono_gc_wbarrier_set_field(NULL, (void**)addr, mono_value_box_checked (d, klass, vtype_buf, &error)); + mono_gc_wbarrier_generic_store((void**)addr, mono_value_box_checked (d, klass, vtype_buf, &error)); mono_error_cleanup (&error); g_free (vtype_buf); } else { From c1ebb8f5a3177053332aa4277befbb174b32571b Mon Sep 17 00:00:00 2001 From: Jonathan Chambers Date: Tue, 23 Oct 2018 15:24:46 -0400 Subject: [PATCH 04/23] Reduce codegen overhead for debugger to single check. Avoid retrieving sequence point until actually needed. Brings use from ~20x slower to ~5x slower when debugger codegen is enabled vs no debugger codegen. --- mono/mini/debugger-agent.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index ca42dc5cdf08..ffeddd807f34 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -1160,6 +1160,20 @@ void mono_debugger_install_runtime_callbacks(MonoDebuggerRuntimeCallbacks* cbs) callbacks = *cbs; } +uint32_t* g_unity_check; +void mono_debugger_install_sequence_point_check(uint32_t* check) +{ + g_unity_check = check; +} + +#define INC_PAUSE_COUNT() do { mono_atomic_inc_i32 (g_unity_check); } while (0) +#define DEC_PAUSE_COUNT() do { mono_atomic_dec_i32 (g_unity_check); } while (0) + +#else + +#define INC_PAUSE_COUNT() +#define DEC_PAUSE_COUNT() + #endif // RUNTIME_IL2CPP /* @@ -3430,7 +3444,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls) } else if (tls->il2cpp_context->frameCount > 0) { for (int frame_index = tls->il2cpp_context->frameCount - 1; frame_index >= 0; --frame_index) { - Il2CppSequencePoint* seq_point = tls->il2cpp_context->executionContexts[frame_index]->currentSequencePoint; + Il2CppSequencePoint* seq_point = il2cpp_get_sequence_point (tls->il2cpp_context->executionContexts[frame_index]->currentSequencePoint); StackFrame* frame = g_new0(StackFrame, 1); MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point); frame->method = sp_method; @@ -4836,6 +4850,7 @@ set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, MonoError inst->seq_point = seqPoint; seqPoint->isActive++; + INC_PAUSE_COUNT(); mono_loader_lock(); g_ptr_array_add(bp->children, inst); @@ -4925,6 +4940,7 @@ static MonoBreakpoint* set_breakpoint_fast(Il2CppSequencePoint *sp, EventRequest inst->seq_point = sp; sp->isActive++; + INC_PAUSE_COUNT(); mono_loader_lock(); g_ptr_array_add(bp->children, inst); @@ -4961,6 +4977,7 @@ clear_breakpoint (MonoBreakpoint *bp) remove_breakpoint(inst); #else inst->seq_point->isActive--; + DEC_PAUSE_COUNT(); #endif g_free (inst); @@ -5038,6 +5055,7 @@ clear_breakpoints_for_domain (MonoDomain *domain) remove_breakpoint (inst); #else inst->seq_point->isActive--; + DEC_PAUSE_COUNT(); #endif g_free (inst); @@ -5854,7 +5872,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int seque #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_STEP, jinfo_get_method (ji), il_offset, ctx, events, suspend_policy); #else - Il2CppSequencePoint* sequence_pt = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint; + Il2CppSequencePoint* sequence_pt = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint); MonoMethod *sp_method = il2cpp_get_seq_point_method(sequence_pt); /* @@ -5998,6 +6016,7 @@ start_single_stepping (void) { #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED int val = mono_atomic_inc_i32 (&ss_count); + INC_PAUSE_COUNT(); if (val == 1) { mono_arch_start_single_stepping (); @@ -6015,6 +6034,7 @@ stop_single_stepping (void) { #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED int val = mono_atomic_dec_i32 (&ss_count); + DEC_PAUSE_COUNT(); if (val == 0) { mono_arch_stop_single_stepping (); @@ -6443,7 +6463,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint } else { if (ss_req->depth == STEP_DEPTH_OVER) { - MonoMethod* currentMethod = il2cpp_get_seq_point_method(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint); + MonoMethod* currentMethod = il2cpp_get_seq_point_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint)); void *seqPointIter = NULL; Il2CppSequencePoint *seqPoint; @@ -6459,7 +6479,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint if (tls->il2cpp_context->frameCount > 1) { - Il2CppSequencePoint* sequencePointForStepOut = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 2]->currentSequencePoint; + Il2CppSequencePoint* sequencePointForStepOut = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 2]->currentSequencePoint); g_assert(sequencePointForStepOut->kind == kSequencePointKind_StepOut); ss_bp_add_one_il2cpp(ss_req, &ss_req_bp_count, &ss_req_bp_cache, sequencePointForStepOut); } @@ -6528,6 +6548,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte DEBUG_PRINTF (1, "[dbg] Starting single step of thread %p (depth=%s).\n", thread, ss_depth_to_string (depth)); ss_req = g_new0 (SingleStepReq, 1); + INC_PAUSE_COUNT(); ss_req->req = req; ss_req->thread = thread; ss_req->size = size; @@ -6553,7 +6574,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte if (tls->il2cpp_context->frameCount > 0) { - Il2CppSequencePoint* seq_point = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint; + Il2CppSequencePoint* seq_point = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint); MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point); ss_req->start_method = sp_method; ss_req->last_method = sp_method; @@ -6669,6 +6690,7 @@ ss_destroy (SingleStepReq *req) ss_stop (ss_req); g_free (ss_req); + DEC_PAUSE_COUNT(); ss_req = NULL; } @@ -6788,7 +6810,7 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point(DebuggerTlsData *tl int frameIndex = tls->il2cpp_context->frameCount - 1; while (frameIndex >= 0) { - Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, tls->exception); + Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint), tls->exception); if (sp) return sp; @@ -6812,7 +6834,7 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point_from_exeption(Debug int frameIndex = tls->il2cpp_context->frameCount - 1; while (frameIndex >= 0) { - sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, exc); + sp = il2cpp_find_catch_sequence_point_in_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint), exc); if (sp) return sp; From 3b831f7243a206564b3c83c744ef54f06b1b062b Mon Sep 17 00:00:00 2001 From: Jonathan Chambers Date: Wed, 14 Nov 2018 16:34:40 -0500 Subject: [PATCH 05/23] Store method pointer, invoker indices, and reverse pinvoke indices in per assembly table rather than in metadata binary file. This is step towards per assembly conversion. --- mono/metadata/metadata-internals.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mono/metadata/metadata-internals.h b/mono/metadata/metadata-internals.h index dd10e13c65c6..7a3c0a565c1d 100644 --- a/mono/metadata/metadata-internals.h +++ b/mono/metadata/metadata-internals.h @@ -195,6 +195,9 @@ struct _MonoImage { /* If the raw data was allocated from a source such as mmap, the allocator may store resource tracking information here. */ void *raw_data_handle; char *raw_data; +#ifdef IL2CPP_ON_MONO + void* il2cpp_codegen_handle; +#endif guint32 raw_data_len; guint8 raw_buffer_used : 1; guint8 raw_data_allocated : 1; From 31422d0924de5c446601fa78b7f4f3c98138d4ad Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Fri, 16 Nov 2018 15:12:59 -0500 Subject: [PATCH 06/23] Make the global break check volatile The Suspend debugger test was hanging intermittently on most platforms. These seemed to occur because the codegen checks for `g_Il2CppDebuggerCheckPointEnabled` were not getting the proper value, and assuming the check point was not set, so the VM would not suspend. This meant that the main thread could not be suspended when the debugger was trying to exit, so the main thread kept looping forever, with out allowing the debugger to exit it. --- mono/mini/debugger-agent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index ffeddd807f34..766693252d5b 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -1161,7 +1161,7 @@ void mono_debugger_install_runtime_callbacks(MonoDebuggerRuntimeCallbacks* cbs) } uint32_t* g_unity_check; -void mono_debugger_install_sequence_point_check(uint32_t* check) +void mono_debugger_install_sequence_point_check(volatile uint32_t* check) { g_unity_check = check; } From 7c741478e90b1d2511da516103dcf1838cf91a54 Mon Sep 17 00:00:00 2001 From: Michael DeRoy Date: Tue, 27 Nov 2018 16:46:18 -0500 Subject: [PATCH 07/23] Remove Class From Codegen headers --- mono/mini/il2cpp-stubs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index bccc70309921..cdc2ca4ae5fa 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -12,6 +12,7 @@ #include "vm/Assembly.h" #include "vm/AssemblyName.h" #include "vm/Class.h" +#include "vm/ClassInlines.h" #include "vm/Domain.h" #include "vm/Field.h" #include "vm/GenericContainer.h" @@ -1823,7 +1824,7 @@ MonoMethod* il2cpp_get_interface_method(MonoClass* klass, MonoClass* itf, int sl IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); return NULL; #else - const VirtualInvokeData* data = il2cpp::vm::Class::GetInterfaceInvokeDataFromVTable((Il2CppClass*)klass, (Il2CppClass*)itf, slot); + const VirtualInvokeData* data = il2cpp::vm::ClassInlines::GetInterfaceInvokeDataFromVTable((Il2CppClass*)klass, (Il2CppClass*)itf, slot); if (!data) return NULL; From afa21ce9a9c2cfc2d2f6650b7e158d11ce85d806 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Fri, 30 Nov 2018 12:28:45 -0500 Subject: [PATCH 08/23] Don't shutdown in mono_runtime_try_shutdown The Mono implementation of mono_runtime_try_shutdown does not actually shut down the VM. Instead, it sets the flags to indicate the VM is shutting down. The VM should actually shutdown in mono_runtime_quit. In some cases, we see this code path taken when processing the CMD_VM_EXIT command. This seems unlikely, but can happen when the code above cannot find a suspended managed thread. If mono_runtime_try_shutdown actually waits for managed threads to complete, it will hang, as the main thread won't be suspended because resume_vm is called just above mono_runtime_try_shutdown. So for IL2CPP mono_runtime_try_shutdown doesn't do anything, but mono_runtime_quit will actually shutdown the VM. --- mono/mini/il2cpp-stubs.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index cdc2ca4ae5fa..ee4c70bde39d 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -503,7 +503,12 @@ MonoDomain* il2cpp_mono_get_root_domain (void) void il2cpp_mono_runtime_quit (void) { - IL2CPP_ASSERT(0 && "This method is not yet implemented"); +#if UNITY_TINY + IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); + return 0; +#else + il2cpp::vm::Runtime::Shutdown(); +#endif } gboolean il2cpp_mono_runtime_is_shutting_down (void) @@ -1265,13 +1270,7 @@ MonoImage* il2cpp_mono_assembly_get_image(MonoAssembly* assembly) gboolean il2cpp_mono_runtime_try_shutdown() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else - il2cpp::vm::Runtime::Shutdown(); - return TRUE; -#endif + return TRUE; } gboolean il2cpp_mono_verifier_is_method_valid_generic_instantiation(MonoMethod* method) From c1aa29730b5bb8a865a70d813cf1def6517bdbca Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Sat, 1 Dec 2018 07:04:08 -0500 Subject: [PATCH 09/23] Fix a build error in Tiny debugger tests --- mono/mini/il2cpp-stubs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index ee4c70bde39d..96e49c6df198 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -505,7 +505,6 @@ void il2cpp_mono_runtime_quit (void) { #if UNITY_TINY IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; #else il2cpp::vm::Runtime::Shutdown(); #endif From 6871e3dd9fd4090db9fdc297c1ce76013d78aa44 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Wed, 21 Nov 2018 14:41:52 -0500 Subject: [PATCH 10/23] Remove all UNITY_TINY #if statements from il2cpp-stubs.cpp Since we run the Tiny profile on the libil2cpp backend, we don't need any differences in this file. --- mono/mini/il2cpp-stubs.cpp | 521 +------------------------------------ 1 file changed, 2 insertions(+), 519 deletions(-) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 96e49c6df198..31a5154526db 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -6,7 +6,6 @@ #include "gc/GarbageCollector.h" #include "gc/WriteBarrier.h" #include "gc/gc_wrapper.h" -#if !UNITY_TINY #include "metadata/FieldLayout.h" #include "metadata/GenericMetadata.h" #include "vm/Assembly.h" @@ -25,7 +24,6 @@ #include "vm/Thread.h" #include "vm/ThreadPoolMs.h" #include "vm/Type.h" -#endif #include "vm/Runtime.h" #include "vm/String.h" #include "vm-utils/Debugger.h" @@ -54,30 +52,18 @@ Il2CppMonoDebugOptions il2cpp_mono_debug_options; static MonoGHashTable *method_signatures; -#if !UNITY_TINY static il2cpp::os::Mutex s_il2cpp_mono_loader_lock(false); -#endif static uint64_t s_il2cpp_mono_loader_lock_tid = 0; MonoMethod* il2cpp_mono_image_get_entry_point (MonoImage *image) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoMethod*)il2cpp::vm::Image::GetEntryPoint((Il2CppImage*)image); -#endif } const char* il2cpp_mono_image_get_filename (MonoImage *monoImage) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else Il2CppImage *image = (Il2CppImage*)monoImage; return image->name; -#endif } const char* il2cpp_mono_image_get_guid (MonoImage *image) @@ -87,32 +73,17 @@ const char* il2cpp_mono_image_get_guid (MonoImage *image) MonoClass* il2cpp_mono_type_get_class (MonoType *type) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*) il2cpp::vm::Type::GetClass((Il2CppType*)type); -#endif } mono_bool il2cpp_mono_type_is_struct (MonoType *type) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Type::IsStruct((Il2CppType*)type); -#endif } mono_bool il2cpp_mono_type_is_reference (MonoType *type) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Type::IsReference((Il2CppType*)type); -#endif } void il2cpp_mono_metadata_free_mh (MonoMethodHeader *mh) @@ -122,10 +93,6 @@ void il2cpp_mono_metadata_free_mh (MonoMethodHeader *mh) Il2CppMonoMethodSignature* il2cpp_mono_method_signature (MonoMethod *m) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else MethodInfo* method = (MethodInfo*)m; if (method_signatures == NULL) @@ -164,7 +131,6 @@ Il2CppMonoMethodSignature* il2cpp_mono_method_signature (MonoMethod *m) mono_g_hash_table_insert(method_signatures, method, sig); return sig; -#endif } static void il2cpp_mono_free_method_signature(gpointer unused1, gpointer value, gpointer unused2) @@ -186,27 +152,18 @@ void il2cpp_mono_free_method_signatures() void il2cpp_mono_method_get_param_names (MonoMethod *m, const char **names) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else MethodInfo* method = (MethodInfo*)m; uint32_t numberOfParameters = il2cpp::vm::Method::GetParamCount(method); for (int i = 0; i < numberOfParameters; ++i) names[i] = il2cpp::vm::Method::GetParamName(method, i); -#endif } mono_bool il2cpp_mono_type_generic_inst_is_valuetype (MonoType *monoType) { - #if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else static const int kBitIsValueType = 1; Il2CppType *type = (Il2CppType*)monoType; const Il2CppTypeDefinition *typeDef = il2cpp::vm::MetadataCache::GetTypeDefinitionFromIndex(type->data.generic_class->typeDefinitionIndex); return (typeDef->bitfield >> (kBitIsValueType - 1)) & 0x1; -#endif } MonoMethodHeader* il2cpp_mono_method_get_header_checked (MonoMethod *method, MonoError *error) @@ -222,12 +179,7 @@ gboolean il2cpp_mono_class_init (MonoClass *klass) MonoVTable* il2cpp_mono_class_vtable (MonoDomain *domain, MonoClass *klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoVTable*)((Il2CppClass*)klass)->vtable; -#endif } MonoClassField* il2cpp_mono_class_get_field_from_name (MonoClass *klass, const char *name) @@ -238,123 +190,64 @@ MonoClassField* il2cpp_mono_class_get_field_from_name (MonoClass *klass, const c int32_t il2cpp_mono_array_element_size (MonoClass *monoClass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else Il2CppClass *klass = (Il2CppClass*)monoClass; return klass->element_size; -#endif } int32_t il2cpp_mono_class_instance_size (MonoClass *klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else + il2cpp::vm::Class::Init(klass); return il2cpp::vm::Class::GetInstanceSize((Il2CppClass*)klass); -#endif } int32_t il2cpp_mono_class_value_size (MonoClass *klass, uint32_t *align) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Class::GetValueSize((Il2CppClass*)klass, align); -#endif } gboolean il2cpp_mono_class_is_assignable_from (MonoClass *klass, MonoClass *oklass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Class::IsAssignableFrom((Il2CppClass*)klass, (Il2CppClass*)oklass); -#endif } MonoClass* il2cpp_mono_class_from_mono_type (MonoType *type) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp::vm::Class::FromIl2CppType((Il2CppType*)type); -#endif } int il2cpp_mono_class_num_fields (MonoClass *klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Class::GetNumFields((Il2CppClass*)klass); -#endif } int il2cpp_mono_class_num_methods (MonoClass *klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Class::GetNumMethods((Il2CppClass*)klass); -#endif } int il2cpp_mono_class_num_properties (MonoClass *klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Class::GetNumProperties((Il2CppClass*)klass); -#endif } MonoClassField* il2cpp_mono_class_get_fields (MonoClass* klass, gpointer *iter) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClassField*)il2cpp::vm::Class::GetFields((Il2CppClass*)klass, iter); -#endif } MonoMethod* il2cpp_mono_class_get_methods (MonoClass* klass, gpointer *iter) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoMethod*)il2cpp::vm::Class::GetMethods((Il2CppClass*)klass, iter); -#endif } MonoProperty* il2cpp_mono_class_get_properties (MonoClass* klass, gpointer *iter) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoProperty*)il2cpp::vm::Class::GetProperties((Il2CppClass*)klass, iter); -#endif } const char* il2cpp_mono_field_get_name (MonoClassField *field) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return il2cpp::vm::Field::GetName((FieldInfo*)field); -#endif } mono_unichar2* il2cpp_mono_string_chars (MonoString *monoStr) @@ -383,12 +276,7 @@ uintptr_t il2cpp_mono_array_length (MonoArray *array) MonoString* il2cpp_mono_string_new (MonoDomain *domain, const char *text) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoString*)il2cpp::vm::String::New(text); -#endif } @@ -400,15 +288,10 @@ MonoString* il2cpp_mono_string_new_checked (MonoDomain *domain, const char *text char* il2cpp_mono_string_to_utf8_checked (MonoString *string_obj, MonoError *error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); Il2CppString *str = (Il2CppString*)string_obj; std::string s = il2cpp::utils::StringUtils::Utf16ToUtf8(str->chars, str->length); return g_strdup(s.c_str()); -#endif } int il2cpp_mono_object_hash (MonoObject* obj) @@ -418,13 +301,8 @@ int il2cpp_mono_object_hash (MonoObject* obj) void* il2cpp_mono_object_unbox (MonoObject *monoObj) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else Il2CppObject *obj = (Il2CppObject*)monoObj; return il2cpp::vm::Object::Unbox(obj); -#endif } void il2cpp_mono_field_set_value (MonoObject *obj, MonoClassField *field, void *value) @@ -434,20 +312,12 @@ void il2cpp_mono_field_set_value (MonoObject *obj, MonoClassField *field, void * void il2cpp_mono_field_static_set_value (MonoVTable *vt, MonoClassField *field, void *value) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Field::StaticSetValue((FieldInfo*)field, value); -#endif } uint32_t il2cpp_mono_gchandle_new_weakref (MonoObject *obj, mono_bool track_resurrection) { -#if UNITY_TINY - return il2cpp::gc::GCHandle::NewWeakref((Il2CppObject*)obj); -#else return il2cpp::gc::GCHandle::NewWeakref((Il2CppObject*)obj, track_resurrection == 0 ? false : true); -#endif } MonoObject* il2cpp_mono_gchandle_get_target (uint32_t gchandle) @@ -467,10 +337,6 @@ void il2cpp_mono_gc_wbarrier_generic_store (void* ptr, MonoObject* value) int il2cpp_mono_reflection_parse_type_checked (char *name, Il2CppMonoTypeNameParse *monoInfo, MonoError *error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else error_init(error); il2cpp::vm::TypeNameParseInfo *pInfo = new il2cpp::vm::TypeNameParseInfo(); std::string nameStr = name; @@ -479,26 +345,16 @@ int il2cpp_mono_reflection_parse_type_checked (char *name, Il2CppMonoTypeNamePar monoInfo->assembly.name = NULL; monoInfo->il2cppTypeNameParseInfo = pInfo; return parser.Parse(); -#endif } void il2cpp_mono_reflection_free_type_info (Il2CppMonoTypeNameParse *info) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else delete (il2cpp::vm::TypeNameParseInfo*)info->il2cppTypeNameParseInfo; -#endif } MonoDomain* il2cpp_mono_get_root_domain (void) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoDomain*)il2cpp::vm::Domain::GetCurrent(); -#endif } void il2cpp_mono_runtime_quit (void) @@ -512,12 +368,7 @@ void il2cpp_mono_runtime_quit (void) gboolean il2cpp_mono_runtime_is_shutting_down (void) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Runtime::IsShuttingDown() ? TRUE : FALSE; -#endif } MonoDomain* il2cpp_mono_domain_get (void) @@ -563,13 +414,8 @@ void il2cpp_mono_set_is_debugger_attached(gboolean attached) char* il2cpp_mono_type_full_name(MonoType* type) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else std::string name = il2cpp::vm::Type::GetName((Il2CppType*)type, IL2CPP_TYPE_NAME_FORMAT_FULL_NAME); return g_strdup(name.c_str()); -#endif } char* il2cpp_mono_method_full_name(MonoMethod* method, gboolean signature) @@ -579,41 +425,22 @@ char* il2cpp_mono_method_full_name(MonoMethod* method, gboolean signature) MonoThread* il2cpp_mono_thread_current() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoThread*)il2cpp::vm::Thread::Current(); -#endif } MonoThread* il2cpp_mono_thread_get_main() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoThread*)il2cpp::vm::Thread::Main(); -#endif } MonoThread* il2cpp_mono_thread_attach(MonoDomain* domain) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoThread*)il2cpp::vm::Thread::Attach((Il2CppDomain*)domain); -#endif } void il2cpp_mono_thread_detach(MonoThread* thread) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Thread::Detach((Il2CppThread*)thread); -#endif } void il2cpp_mono_domain_lock(MonoDomain* domain) @@ -637,12 +464,7 @@ guint il2cpp_mono_aligned_addr_hash(gconstpointer ptr) MonoGenericInst* il2cpp_mono_metadata_get_generic_inst(int type_argc, MonoType** type_argv) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoGenericInst*)il2cpp::vm::MetadataCache::GetGenericInst((Il2CppType**)type_argv, type_argc); -#endif } MonoMethod* il2cpp_mono_get_method_checked(MonoImage* image, guint32 token, MonoClass* klass, MonoGenericContext* context, MonoError* error) @@ -658,13 +480,8 @@ SgenDescriptor il2cpp_mono_gc_make_root_descr_all_refs(int numbits) int il2cpp_mono_gc_register_root_wbarrier (char *start, size_t size, MonoGCDescriptor descr, MonoGCRootSource source, void *key, const char *msg) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else il2cpp::gc::GarbageCollector::RegisterRoot(start, size); return 1; -#endif } MonoGCDescriptor il2cpp_mono_gc_make_vector_descr (void) @@ -685,30 +502,17 @@ void il2cpp_mono_class_setup_supertypes(MonoClass* klass) void il2cpp_mono_class_setup_vtable(MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Class::Init((Il2CppClass*)klass); -#endif } void il2cpp_mono_class_setup_methods(MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Class::SetupMethods((Il2CppClass*)klass); -#endif } gboolean il2cpp_mono_class_field_is_special_static(MonoClassField* field) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Field::IsNormalStatic((FieldInfo*)field) ? FALSE : TRUE; -#endif } guint32 il2cpp_mono_class_field_get_special_static_type(MonoClassField* field) @@ -719,84 +523,51 @@ guint32 il2cpp_mono_class_field_get_special_static_type(MonoClassField* field) MonoGenericContext* il2cpp_mono_class_get_context(MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoGenericContext*)&((Il2CppClass*)klass)->generic_class->context; -#endif } MonoGenericContext* il2cpp_mono_method_get_context(MonoMethod* monoMethod) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else MethodInfo * method = (MethodInfo*)monoMethod; if (!method->is_inflated || method->is_generic) return NULL; return (MonoGenericContext*) &((MethodInfo*)method)->genericMethod->context; -#endif } MonoGenericContainer* il2cpp_mono_method_get_generic_container(MonoMethod* monoMethod) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else MethodInfo * method = (MethodInfo*)monoMethod; if (method->is_inflated || !method->is_generic) return NULL; return (MonoGenericContainer*) method->genericContainer; -#endif } MonoMethod* il2cpp_mono_class_inflate_generic_method_full_checked(MonoMethod* method, MonoClass* klass_hint, MonoGenericContext* context, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); return (MonoMethod*) il2cpp::metadata::GenericMetadata::Inflate((MethodInfo*)method, (Il2CppClass*)klass_hint, (Il2CppGenericContext*)context); -#endif } MonoMethod* il2cpp_mono_class_inflate_generic_method_checked(MonoMethod* method, MonoGenericContext* context, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); return (MonoMethod*)il2cpp::metadata::GenericMetadata::Inflate((MethodInfo*)method, NULL, (Il2CppGenericContext*)context); -#endif } void il2cpp_mono_loader_lock() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else s_il2cpp_mono_loader_lock.Lock(); s_il2cpp_mono_loader_lock_tid = il2cpp::os::Thread::CurrentThreadId(); -#endif } void il2cpp_mono_loader_unlock() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else s_il2cpp_mono_loader_lock_tid = 0; s_il2cpp_mono_loader_lock.Unlock(); -#endif } void il2cpp_mono_loader_lock_track_ownership(gboolean track) @@ -805,12 +576,7 @@ void il2cpp_mono_loader_lock_track_ownership(gboolean track) gboolean il2cpp_mono_loader_lock_is_owned_by_self() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return s_il2cpp_mono_loader_lock_tid == il2cpp::os::Thread::CurrentThreadId(); -#endif } gpointer il2cpp_mono_method_get_wrapper_data(MonoMethod* method, guint32 id) @@ -821,43 +587,25 @@ gpointer il2cpp_mono_method_get_wrapper_data(MonoMethod* method, guint32 id) char* il2cpp_mono_type_get_name_full(MonoType* type, MonoTypeNameFormat format) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else std::string name = il2cpp::vm::Type::GetName((Il2CppType*)type, (Il2CppTypeNameFormat)format); return g_strdup(name.c_str()); -#endif } gboolean il2cpp_mono_class_is_nullable(MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Class::IsNullable((Il2CppClass*)klass); -#endif +# } MonoGenericContainer* il2cpp_mono_class_get_generic_container(MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoGenericContainer*)il2cpp::vm::Class::GetGenericContainer((Il2CppClass*)klass); -#endif } void il2cpp_mono_class_setup_interfaces(MonoClass* klass, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else error_init(error); il2cpp::vm::Class::SetupInterfaces((Il2CppClass*)klass); -#endif } enum { @@ -882,10 +630,6 @@ enum { static gboolean method_nonpublic (MethodInfo* method, gboolean start_klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else switch (method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) { case METHOD_ATTRIBUTE_ASSEM: return (start_klass || il2cpp_defaults.generic_ilist_class); @@ -896,15 +640,10 @@ method_nonpublic (MethodInfo* method, gboolean start_klass) default: return TRUE; } -#endif } GPtrArray* il2cpp_mono_class_get_methods_by_name(MonoClass* il2cppMonoKlass, const char* name, guint32 bflags, gboolean ignore_case, gboolean allow_ctors, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else GPtrArray *array; Il2CppClass *klass = (Il2CppClass*)il2cppMonoKlass; Il2CppClass *startklass; @@ -988,7 +727,6 @@ GPtrArray* il2cpp_mono_class_get_methods_by_name(MonoClass* il2cppMonoKlass, con g_free (method_slots);*/ return array; -#endif } gpointer il2cpp_mono_ldtoken_checked(MonoImage* image, guint32 token, MonoClass** handle_class, MonoGenericContext* context, MonoError* error) @@ -999,12 +737,7 @@ gpointer il2cpp_mono_ldtoken_checked(MonoImage* image, guint32 token, MonoClass* MonoClass* il2cpp_mono_class_from_generic_parameter_internal(MonoGenericParam* param) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp::vm::Class::FromGenericParameter((Il2CppGenericParameter*)param); -#endif } MonoClass* il2cpp_mono_class_load_from_name(MonoImage* image, const char* name_space, const char* name) @@ -1015,13 +748,8 @@ MonoClass* il2cpp_mono_class_load_from_name(MonoImage* image, const char* name_s MonoGenericClass* il2cpp_mono_class_get_generic_class(MonoClass* monoClass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else Il2CppClass *klass = (Il2CppClass*)monoClass; return (MonoGenericClass*)klass->generic_class; -#endif } MonoInternalThread* il2cpp_mono_thread_internal_current() @@ -1036,28 +764,16 @@ gboolean il2cpp_mono_thread_internal_is_current(MonoInternalThread* thread) void il2cpp_mono_thread_internal_abort(MonoInternalThread* thread, gboolean appdomain_unload) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Thread::RequestAbort((Il2CppInternalThread*)thread); -#endif } void il2cpp_mono_thread_internal_reset_abort(MonoInternalThread* thread) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Thread::ResetAbort((Il2CppInternalThread*)thread); -#endif } gunichar2* il2cpp_mono_thread_get_name(MonoInternalThread* this_obj, guint32* name_len) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else std::string name = il2cpp::vm::Thread::GetName((Il2CppInternalThread*)this_obj); if (name_len != NULL) @@ -1066,17 +782,12 @@ gunichar2* il2cpp_mono_thread_get_name(MonoInternalThread* this_obj, guint32* na if (name.empty()) return NULL; return g_utf8_to_utf16(name.c_str(), name.size(), NULL, NULL, NULL); -#endif } void il2cpp_mono_thread_set_name_internal(MonoInternalThread* this_obj, MonoString* name, gboolean permanent, gboolean reset, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Thread::SetName((Il2CppInternalThread*)this_obj, (Il2CppString*)name); error_init(error); -#endif } void il2cpp_mono_thread_suspend_all_other_threads() @@ -1097,42 +808,25 @@ Il2CppMonoRuntimeExceptionHandlingCallbacks* il2cpp_mono_get_eh_callbacks() void il2cpp_mono_nullable_init(guint8* buf, MonoObject* value, MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::vm::Object::NullableInit(buf, (Il2CppObject*)value, (Il2CppClass*)klass); -#endif } MonoObject* il2cpp_mono_value_box_checked(MonoDomain* domain, MonoClass* klass, gpointer value, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); return (MonoObject*)il2cpp::vm::Object::Box((Il2CppClass*)klass, value); -#endif } void il2cpp_mono_field_static_get_value_checked(MonoVTable* vt, MonoClassField* field, void* value, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else error_init(error); il2cpp::vm::Field::StaticGetValue((FieldInfo*)field, value); -#endif } void il2cpp_mono_field_static_get_value_for_thread(MonoInternalThread* thread, MonoVTable* vt, MonoClassField* field, void* value, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else error_init(error); il2cpp::vm::Field::StaticGetValueForThread((FieldInfo*)field, value, (Il2CppInternalThread*)thread); -#endif } MonoObject* il2cpp_mono_field_get_value_object_checked(MonoDomain* domain, MonoClassField* field, MonoObject* obj, MonoError* error) @@ -1143,13 +837,8 @@ MonoObject* il2cpp_mono_field_get_value_object_checked(MonoDomain* domain, MonoC MonoObject* il2cpp_mono_object_new_checked(MonoDomain* domain, MonoClass* klass, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); return (MonoObject*)il2cpp::vm::Object::New((Il2CppClass*)klass); -#endif } MonoString* il2cpp_mono_ldstr_checked(MonoDomain* domain, MonoImage* image, guint32 idx, MonoError* error) @@ -1160,17 +849,12 @@ MonoString* il2cpp_mono_ldstr_checked(MonoDomain* domain, MonoImage* image, guin MonoObject* il2cpp_mono_runtime_try_invoke(MonoMethod* method, void* obj, void** params, MonoObject** exc, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); if (((MethodInfo*)method)->klass->valuetype) obj = static_cast(obj) - 1; return (MonoObject*)il2cpp::vm::Runtime::Invoke((MethodInfo*)method, obj, params, (Il2CppException**)exc); -#endif } MonoObject* il2cpp_mono_runtime_invoke_checked(MonoMethod* method, void* obj, void** params, MonoError* error) @@ -1183,28 +867,17 @@ void il2cpp_mono_gc_base_init() { } -#if !UNITY_TINY static il2cpp::os::Mutex s_il2cpp_gc_root_lock(false); -#endif int il2cpp_mono_gc_register_root(char* start, size_t size, MonoGCDescriptor descr, MonoGCRootSource source, const char* msg) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else il2cpp::gc::GarbageCollector::RegisterRoot(start, size); return 1; -#endif } void il2cpp_mono_gc_deregister_root(char* addr) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::gc::GarbageCollector::UnregisterRoot(addr); -#endif } #ifndef HOST_WIN32 @@ -1222,12 +895,7 @@ gboolean il2cpp_mono_gc_is_moving() gint32 il2cpp_mono_environment_exitcode_get() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Runtime::GetExitCode(); -#endif } void il2cpp_mono_environment_exitcode_set(gint32 value) @@ -1237,34 +905,21 @@ void il2cpp_mono_environment_exitcode_set(gint32 value) void il2cpp_mono_threadpool_suspend() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else #if NET_4_0 il2cpp::vm::ThreadPoolMs::Suspend(); #endif // NET_4_0 -#endif } void il2cpp_mono_threadpool_resume() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else #if NET_4_0 il2cpp::vm::ThreadPoolMs::Resume(); #endif // NET_4_0 -#endif } MonoImage* il2cpp_mono_assembly_get_image(MonoAssembly* assembly) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoImage*)il2cpp::vm::Assembly::GetImage((Il2CppAssembly*)assembly); -#endif } gboolean il2cpp_mono_runtime_try_shutdown() @@ -1274,10 +929,6 @@ gboolean il2cpp_mono_runtime_try_shutdown() gboolean il2cpp_mono_verifier_is_method_valid_generic_instantiation(MonoMethod* method) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else if (!method) return FALSE; @@ -1285,15 +936,10 @@ gboolean il2cpp_mono_verifier_is_method_valid_generic_instantiation(MonoMethod* return TRUE; return FALSE; -#endif } MonoType* il2cpp_mono_reflection_get_type_checked(MonoImage* rootimage, MonoImage* image, Il2CppMonoTypeNameParse* info, gboolean ignorecase, gboolean* type_resolve, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); Il2CppClass *klass = il2cpp::vm::Image::FromTypeNameParseInfo((Il2CppImage*)image, *((il2cpp::vm::TypeNameParseInfo*)info->il2cppTypeNameParseInfo), ignorecase); @@ -1301,28 +947,17 @@ MonoType* il2cpp_mono_reflection_get_type_checked(MonoImage* rootimage, MonoImag return NULL; return (MonoType*)il2cpp::vm::Class::GetType(klass); -#endif } MonoReflectionAssemblyHandle il2cpp_mono_assembly_get_object_handle(MonoDomain* domain, MonoAssembly* assembly, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoReflectionAssemblyHandle)il2cpp::vm::Reflection::GetAssemblyObject((const Il2CppAssembly *)assembly); -#endif } MonoReflectionType* il2cpp_mono_type_get_object_checked(MonoDomain* domain, MonoType* type, MonoError* error) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else error_init(error); return (MonoReflectionType*)il2cpp::vm::Reflection::GetTypeObject((const Il2CppType*)type); -#endif } void il2cpp_mono_network_init() @@ -1507,12 +1142,7 @@ gboolean il2cpp_mono_class_has_parent (MonoClass *klass, MonoClass *parent) MonoGenericParam* il2cpp_mono_generic_container_get_param (MonoGenericContainer *gc, int i) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoGenericParam*)il2cpp::vm::GenericContainer::GetGenericParameter((Il2CppGenericContainer*)gc, i); -#endif } gboolean il2cpp_mono_find_seq_point (MonoDomain *domain, MonoMethod *method, gint32 il_offset, MonoSeqPointInfo **info, SeqPoint *seq_point) @@ -1581,12 +1211,7 @@ void* il2cpp_mono_gc_alloc_fixed (size_t size, void* descr, MonoGCRootSource sou typedef void* (*Il2CppMonoGCLockedCallbackFunc) (void *data); void* il2cpp_mono_gc_invoke_with_gc_lock (Il2CppMonoGCLockedCallbackFunc func, void *data) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return il2cpp::gc::GarbageCollector::CallWithAllocLockHeld (func, data); -#endif } // These functions expose the IL2CPP VM C++ API to C @@ -1606,11 +1231,6 @@ MonoAssembly* il2cpp_domain_get_assemblies_iter(MonoAppDomain *domain, void* *it if (!iter) return NULL; -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else - il2cpp::vm::AssemblyVector* assemblies = il2cpp::vm::Assembly::GetAllAssemblies(); if (!*iter) @@ -1634,7 +1254,6 @@ MonoAssembly* il2cpp_domain_get_assemblies_iter(MonoAppDomain *domain, void* *it } return NULL; -#endif } void il2cpp_start_debugger_thread() @@ -1697,150 +1316,85 @@ gboolean il2cpp_mono_methods_match(MonoMethod* left, MonoMethod* right) MonoClass* il2cpp_class_get_nested_types_accepts_generic(MonoClass *monoClass, void* *iter) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else Il2CppClass *klass = (Il2CppClass*)monoClass; if (klass->generic_class) return NULL; return (MonoClass*)il2cpp::vm::Class::GetNestedTypes(klass, iter); -#endif } MonoClass* il2cpp_defaults_object_class() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp_defaults.object_class; -#endif } guint8 il2cpp_array_rank(MonoArray *monoArr) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else Il2CppArray *arr = (Il2CppArray*)monoArr; return arr->klass->rank; -#endif } const char* il2cpp_image_name(MonoImage *monoImage) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else Il2CppImage *image = (Il2CppImage*)monoImage; return image->name; -#endif } guint8* il2cpp_field_get_address(MonoObject *obj, MonoClassField *monoField) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else FieldInfo *field = (FieldInfo*)monoField; return (guint8*)obj + field->offset; -#endif } MonoType* il2cpp_mono_object_get_type(MonoObject* object) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoType*)&(((Il2CppObject*)object)->klass->byval_arg); -#endif } MonoClass* il2cpp_defaults_exception_class() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp_defaults.exception_class; -#endif } MonoImage* il2cpp_defaults_corlib_image() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoImage*)il2cpp_defaults.corlib; -#endif } bool il2cpp_method_is_string_ctor(const MonoMethod * method) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else MethodInfo* methodInfo = (MethodInfo*)method; return methodInfo->klass == il2cpp_defaults.string_class && !strcmp (methodInfo->name, ".ctor"); -#endif } MonoClass* il2cpp_defaults_void_class() { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp_defaults.void_class; -#endif } void il2cpp_set_var(guint8* newValue, void *value, MonoType *localVariableTypeMono) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); -#else il2cpp::metadata::SizeAndAlignment sa = il2cpp::metadata::FieldLayout::GetTypeSizeAndAlignment((const Il2CppType*)localVariableTypeMono); if (((Il2CppType*)localVariableTypeMono)->byref) memcpy(*(void**)value, newValue, sa.size); else memcpy(value, newValue, sa.size); -#endif } MonoMethod* il2cpp_get_interface_method(MonoClass* klass, MonoClass* itf, int slot) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else const VirtualInvokeData* data = il2cpp::vm::ClassInlines::GetInterfaceInvokeDataFromVTable((Il2CppClass*)klass, (Il2CppClass*)itf, slot); if (!data) return NULL; return (MonoMethod*)data->method; -#endif } gboolean il2cpp_field_is_deleted(MonoClassField *field) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else return il2cpp::vm::Field::IsDeleted((FieldInfo*)field); -#endif } -#if !UNITY_TINY struct TypeIterState { il2cpp::vm::AssemblyVector* assemblies; @@ -1849,17 +1403,12 @@ struct TypeIterState il2cpp::vm::TypeVector types; il2cpp::vm::TypeVector::iterator type; }; -#endif MonoClass* il2cpp_iterate_loaded_classes(void* *iter) { if (!iter) return NULL; -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else if (!*iter) { TypeIterState *state = new TypeIterState(); @@ -1891,7 +1440,6 @@ MonoClass* il2cpp_iterate_loaded_classes(void* *iter) } return (MonoClass*)*state->type; -#endif } const char** il2cpp_get_source_files_for_type(MonoClass *klass, int *count) @@ -1905,54 +1453,34 @@ const char** il2cpp_get_source_files_for_type(MonoClass *klass, int *count) MonoMethod* il2cpp_method_get_generic_definition(MonoMethodInflated *imethod) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else MethodInfo *method = (MethodInfo*)imethod; if (!method->is_inflated || method->is_generic) return NULL; return (MonoMethod*)((MethodInfo*)imethod)->genericMethod->methodDefinition; -#endif } MonoGenericInst* il2cpp_method_get_generic_class_inst(MonoMethodInflated *imethod) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else MethodInfo *method = (MethodInfo*)imethod; if (!method->is_inflated || method->is_generic) return NULL; return (MonoGenericInst*)method->genericMethod->context.class_inst; -#endif } MonoClass* il2cpp_generic_class_get_container_class(MonoGenericClass *gclass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp::vm::GenericClass::GetTypeDefinition((Il2CppGenericClass*)gclass); -#endif } MonoClass* il2cpp_mono_get_string_class (void) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoClass*)il2cpp_defaults.string_class; -#endif } Il2CppSequencePoint* il2cpp_get_sequence_point(int id) @@ -1966,13 +1494,8 @@ Il2CppSequencePoint* il2cpp_get_sequence_point(int id) char* il2cpp_assembly_get_full_name(MonoAssembly *assembly) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else std::string s = il2cpp::vm::AssemblyName::AssemblyNameToString(assembly->aname); return g_strdup(s.c_str()); -#endif } const MonoMethod* il2cpp_get_seq_point_method(Il2CppSequencePoint *seqPoint) @@ -1986,35 +1509,20 @@ const MonoMethod* il2cpp_get_seq_point_method(Il2CppSequencePoint *seqPoint) const MonoClass* il2cpp_get_class_from_index(int index) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else if (index < 0) return NULL; return il2cpp::vm::MetadataCache::GetTypeInfoFromTypeIndex(index); -#endif } const MonoType* il2cpp_get_type_from_index(int index) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return il2cpp::vm::MetadataCache::GetIl2CppTypeFromIndex(index); -#endif } const MonoType* il2cpp_type_inflate(MonoType* type, const MonoGenericContext* context) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return il2cpp::metadata::GenericMetadata::InflateIfNeeded(type, context, true); -#endif } void il2cpp_debugger_get_method_execution_context_and_header_Info(const MonoMethod* method, uint32_t* executionContextInfoCount, const Il2CppMethodExecutionContextInfo **executionContextInfo, const Il2CppMethodHeaderInfo **headerInfo, const Il2CppMethodScope **scopes) @@ -2035,12 +1543,7 @@ Il2CppThreadUnwindState* il2cpp_debugger_get_thread_context () MonoGenericClass* il2cpp_m_type_get_generic_class(MonoType* type) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoGenericClass*)((Il2CppType*)type)->data.generic_class; -#endif } mono_bool il2cpp_mono_image_is_dynamic(MonoImage *image) @@ -2050,42 +1553,22 @@ mono_bool il2cpp_mono_image_is_dynamic(MonoImage *image) const MonoAssembly* il2cpp_m_domain_get_corlib (MonoDomain *domain) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return il2cpp::vm::Image::GetAssembly(il2cpp_defaults_corlib_image()); -#endif } MonoGenericContext* il2cpp_mono_generic_class_get_context (MonoGenericClass *gclass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return il2cpp::vm::GenericClass::GetContext((Il2CppGenericClass*)gclass); -#endif } mono_bool il2cpp_m_class_is_initialized (MonoClass* klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return false; -#else return ((Il2CppClass*)klass)->initialized; -#endif } MonoType* il2cpp_mono_class_get_byref_type (MonoClass *klass) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return NULL; -#else return (MonoType*)il2cpp::vm::Class::GetByrefType((Il2CppClass*)klass); -#endif } } From 4bd70642e2cb610c931cc1e2c5e871f7f411143b Mon Sep 17 00:00:00 2001 From: Brian Raderman Date: Mon, 26 Nov 2018 15:57:17 -0500 Subject: [PATCH 11/23] Tiny debugger tests * Ignoring the EventSets test because it tests exceptions. * Fixing the vm.Exit() path that doesn't use System.Environment.Exit(). --- mono/mini/debugger-agent.c | 4 ++-- mono/mini/il2cpp-stubs.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 766693252d5b..7c457d269609 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -8750,11 +8750,11 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf) while (suspend_count > 0) resume_vm (); + mono_environment_exitcode_set (exit_code); + if (!mono_runtime_try_shutdown ()) break; - mono_environment_exitcode_set (exit_code); - /* Suspend all managed threads since the runtime is going away */ DEBUG_PRINTF (1, "Suspending all threads...\n"); mono_thread_suspend_all_other_threads (); diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 31a5154526db..23e418446ef8 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -900,7 +900,7 @@ gint32 il2cpp_mono_environment_exitcode_get() void il2cpp_mono_environment_exitcode_set(gint32 value) { - IL2CPP_ASSERT(0 && "This method is not yet implemented"); + il2cpp::vm::Runtime::SetExitCode(value); } void il2cpp_mono_threadpool_suspend() From 894596ad7f79625f1f739863365af35c392dc26a Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Mon, 3 Dec 2018 10:24:10 -0500 Subject: [PATCH 12/23] Remove a stray # character --- mono/mini/il2cpp-stubs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 23e418446ef8..6a3bdc5113a5 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -594,7 +594,6 @@ char* il2cpp_mono_type_get_name_full(MonoType* type, MonoTypeNameFormat format) gboolean il2cpp_mono_class_is_nullable(MonoClass* klass) { return il2cpp::vm::Class::IsNullable((Il2CppClass*)klass); -# } MonoGenericContainer* il2cpp_mono_class_get_generic_container(MonoClass* klass) From 0bd828badb3e8968070a895a9274c06162570e03 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Mon, 3 Dec 2018 10:31:49 -0500 Subject: [PATCH 13/23] Move the exit code setting back after try_shutdown This reverts part of 78cc586d935f2009058602f2bd9adedca1442442, now that `mono_runtime_try_shutdown` does not actually shut down, but instead does nothing with IL2CPP. --- mono/mini/debugger-agent.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 7c457d269609..766693252d5b 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -8750,11 +8750,11 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf) while (suspend_count > 0) resume_vm (); - mono_environment_exitcode_set (exit_code); - if (!mono_runtime_try_shutdown ()) break; + mono_environment_exitcode_set (exit_code); + /* Suspend all managed threads since the runtime is going away */ DEBUG_PRINTF (1, "Suspending all threads...\n"); mono_thread_suspend_all_other_threads (); From dc5f82b9a61ccf637037baee3542369ff96ac67d Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Fri, 30 Nov 2018 12:28:45 -0500 Subject: [PATCH 14/23] Don't shutdown in mono_runtime_try_shutdown The Mono implementation of mono_runtime_try_shutdown does not actually shut down the VM. Instead, it sets the flags to indicate the VM is shutting down. The VM should actually shutdown in mono_runtime_quit. In some cases, we see this code path taken when processing the CMD_VM_EXIT command. This seems unlikely, but can happen when the code above cannot find a suspended managed thread. If mono_runtime_try_shutdown actually waits for managed threads to complete, it will hang, as the main thread won't be suspended because resume_vm is called just above mono_runtime_try_shutdown. So for IL2CPP mono_runtime_try_shutdown doesn't do anything, but mono_runtime_quit will actually shutdown the VM. --- mono/mini/il2cpp-stubs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 6a3bdc5113a5..145ffe57117d 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -361,6 +361,7 @@ void il2cpp_mono_runtime_quit (void) { #if UNITY_TINY IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); + return 0; #else il2cpp::vm::Runtime::Shutdown(); #endif From 359132ddd35c52edd5771b4b4b3b9bee80adf872 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Mon, 3 Dec 2018 11:59:49 -0500 Subject: [PATCH 15/23] Shutdown the runtime properly for Tiny with the debugger --- mono/mini/il2cpp-stubs.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 145ffe57117d..083d34ca656b 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -359,12 +359,7 @@ MonoDomain* il2cpp_mono_get_root_domain (void) void il2cpp_mono_runtime_quit (void) { -#if UNITY_TINY - IL2CPP_ASSERT(0 && "Not implemented yet for tiny"); - return 0; -#else il2cpp::vm::Runtime::Shutdown(); -#endif } gboolean il2cpp_mono_runtime_is_shutting_down (void) @@ -792,7 +787,6 @@ void il2cpp_mono_thread_set_name_internal(MonoInternalThread* this_obj, MonoStri void il2cpp_mono_thread_suspend_all_other_threads() { - IL2CPP_ASSERT(0 && "This method is not yet implemented"); } void il2cpp_mono_stack_mark_record_size(MonoThreadInfo* info, HandleStackMark* stackmark, const char* func_name) From 2188d961b32fddab495752ff0fdf4b2e33f8ef53 Mon Sep 17 00:00:00 2001 From: Jonathan Chambers Date: Wed, 21 Nov 2018 10:32:06 -0500 Subject: [PATCH 16/23] Produce debugger information per assembly. Collect sequence points per assembly Retrieve sequence point information per image Write all debugger structures to a single file for each assembly Write codegen and debugger structures as C code. This saves ~40% compile time on MSVC --- mono/mini/debugger-agent.c | 61 +++++++++++++++++++------------------- mono/mini/debugger-agent.h | 2 +- mono/mini/il2cpp-compat.h | 6 ++-- mono/mini/il2cpp-stubs.cpp | 36 ++++++++++++---------- 4 files changed, 57 insertions(+), 48 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 766693252d5b..c5d843069972 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -122,7 +122,6 @@ #ifdef RUNTIME_IL2CPP extern Il2CppMonoDefaults il2cpp_mono_defaults; extern Il2CppMonoDebugOptions il2cpp_mono_debug_options; -const Il2CppDebuggerMetadataRegistration *g_il2cpp_metadata; #endif @@ -2300,10 +2299,9 @@ static GPtrArray *ids [ID_NUM]; static GHashTable* s_jit_info_hashtable; -void mono_debugger_il2cpp_init (const Il2CppDebuggerMetadataRegistration *data) +void mono_debugger_il2cpp_init () { s_jit_info_hashtable = g_hash_table_new_full(mono_aligned_addr_hash, NULL, NULL, NULL); - g_il2cpp_metadata = data; debug_options.native_debugger_break = FALSE; } @@ -3882,7 +3880,7 @@ static void #ifndef RUNTIME_IL2CPP process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx, GSList *events, int suspend_policy) #else -process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx, GSList *events, int suspend_policy, uint64_t il2cpp_seqpoint_id) +process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx, GSList *events, int suspend_policy, Il2CppSequencePoint* sequencePoint) #endif { Buffer buf; @@ -3973,7 +3971,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx case EVENT_KIND_METHOD_EXIT: buffer_add_methodid (&buf, domain, (MonoMethod *)arg); #if defined(RUNTIME_IL2CPP) && defined(IL2CPP_DEBUGGER_TESTS) - buffer_add_long (&buf, il2cpp_seqpoint_id); + buffer_add_long (&buf, sequencePoint->id); #endif break; case EVENT_KIND_ASSEMBLY_LOAD: @@ -3998,7 +3996,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx buffer_add_methodid (&buf, domain, (MonoMethod *)arg); buffer_add_long (&buf, il_offset); #if defined(RUNTIME_IL2CPP) && defined(IL2CPP_DEBUGGER_TESTS) - buffer_add_long (&buf, il2cpp_seqpoint_id); + buffer_add_long (&buf, sequencePoint->id); #endif break; case EVENT_KIND_VM_START: @@ -4012,7 +4010,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx DebuggerEventInfo *ei = (DebuggerEventInfo *)arg; buffer_add_objid (&buf, ei->exc); #if defined(RUNTIME_IL2CPP) && defined(IL2CPP_DEBUGGER_TESTS) - buffer_add_long(&buf, il2cpp_seqpoint_id); + buffer_add_long(&buf, sequencePoint->id); #endif /* * We are not yet suspending, so get_objref () will not keep this object alive. So we need to do it @@ -4117,7 +4115,7 @@ process_profiler_event (EventKind event, gpointer arg) #ifndef RUNTIME_IL2CPP process_event (event, arg, 0, NULL, events, suspend_policy); #else - process_event (event, arg, 0, NULL, events, suspend_policy, 0); + process_event (event, arg, 0, NULL, events, suspend_policy, NULL); #endif } @@ -5719,7 +5717,7 @@ mono_debugger_agent_user_break (void) #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy); #else - process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy, 0); + process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy, NULL); #endif } else if (debug_options.native_debugger_break) { G_BREAKPOINT (); @@ -5746,7 +5744,7 @@ static void #ifndef RUNTIME_IL2CPP process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal) #else -process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int sequencePointId) +process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, Il2CppSequencePoint* sequencePoint) #endif { MonoJitInfo *ji; @@ -5862,7 +5860,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int seque #ifndef RUNTIME_IL2CPP events = create_event_list (EVENT_KIND_STEP, reqs, ji, NULL, &suspend_policy); #else - events = create_event_list(EVENT_KIND_STEP, reqs, il2cpp_get_sequence_point(sequencePointId), NULL, &suspend_policy); + events = create_event_list(EVENT_KIND_STEP, reqs, sequencePoint, NULL, &suspend_policy); #endif g_ptr_array_free (reqs, TRUE); @@ -5898,7 +5896,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int seque if(!ss_update_il2cpp(ss_req,tls,ctx,sequence_pt)) return; - process_event(EVENT_KIND_STEP, sp_method, sequence_pt->ilOffset, NULL, events, suspend_policy, sequencePointId); + process_event(EVENT_KIND_STEP, sp_method, sequence_pt->ilOffset, NULL, events, suspend_policy, sequencePoint); #endif } @@ -5943,7 +5941,7 @@ void #ifndef RUNTIME_IL2CPP debugger_agent_single_step_from_context (MonoContext *ctx) #else -debugger_agent_single_step_from_context (MonoContext *ctx, int sequencePointId) +debugger_agent_single_step_from_context (MonoContext *ctx, Il2CppSequencePoint* sequencePoint) #endif { DebuggerTlsData *tls; @@ -5972,7 +5970,7 @@ debugger_agent_single_step_from_context (MonoContext *ctx, int sequencePointId) #else save_thread_context(NULL); - process_single_step_inner(tls, FALSE, sequencePointId); + process_single_step_inner(tls, FALSE, sequencePoint); #endif } @@ -6745,7 +6743,7 @@ mono_debugger_agent_debug_log (int level, MonoString *category, MonoString *mess #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_USER_LOG, &ei, 0, NULL, events, suspend_policy); #else - process_event (EVENT_KIND_USER_LOG, &ei, 0, NULL, events, suspend_policy, 0); + process_event (EVENT_KIND_USER_LOG, &ei, 0, NULL, events, suspend_policy, NULL); #endif g_free (ei.category); @@ -6780,7 +6778,7 @@ mono_debugger_agent_unhandled_exception (MonoException *exc) #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy); #else - process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, 0); + process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, NULL); #endif } #endif @@ -6930,7 +6928,7 @@ unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *s } } - process_event(EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, sequencePoint ? sequencePoint->id : 0); + process_event(EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, sequencePoint); if (tls) tls->exception = NULL; @@ -6975,7 +6973,7 @@ mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL); #else - process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, 0); + process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, NULL); #endif return; } @@ -7004,7 +7002,7 @@ mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL); #else - process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, 0); + process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, NULL); #endif return; } @@ -7064,7 +7062,7 @@ mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, suspend_policy); #else - process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, suspend_policy, 0); + process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, suspend_policy, NULL); #endif if (tls) @@ -10404,15 +10402,17 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g buffer_add_int(buf, uniqueFileSequencePoints->len); for (i = 0; i < uniqueFileSequencePoints->len; ++i) { Il2CppSequencePoint* sequencePoint = g_ptr_array_index(uniqueFileSequencePoints, i); - buffer_add_string(buf, g_il2cpp_metadata->sequencePointSourceFiles[sequencePoint->sourceFileIndex].file); + Il2CppSequencePointSourceFile* sourceFile = il2cpp_debug_get_source_file (mono_class_get_image (mono_method_get_class (method)), sequencePoint->sourceFileIndex); + buffer_add_string(buf, sourceFile->file); if (CHECK_PROTOCOL_VERSION(2, 14)) { - buffer_add_data(buf, g_il2cpp_metadata->sequencePointSourceFiles[sequencePoint->sourceFileIndex].hash, 16); + buffer_add_data(buf, sourceFile->hash, 16); } } } else { if (uniqueFileSequencePoints->len > 0) { - buffer_add_string(buf, g_il2cpp_metadata->sequencePointSourceFiles[((Il2CppSequencePoint*)g_ptr_array_index(uniqueFileSequencePoints, 0))->sourceFileIndex].file); + Il2CppSequencePointSourceFile* sourceFile = il2cpp_debug_get_source_file (mono_class_get_image (mono_method_get_class (method)), ((Il2CppSequencePoint*)g_ptr_array_index(uniqueFileSequencePoints, 0))->sourceFileIndex); + buffer_add_string(buf, sourceFile->file); } else { buffer_add_string(buf, ""); } @@ -10436,7 +10436,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g if (sequencePoint->kind == kSequencePointKind_StepOut) continue; - DEBUG_PRINTF(10, "IL%x -> %s:%d %d %d %d\n", sequencePoint->ilOffset, g_il2cpp_metadata->sequencePointSourceFiles[sequencePoint->sourceFileIndex], + DEBUG_PRINTF(10, "IL%x -> %s:%d %d %d %d\n", sequencePoint->ilOffset, il2cpp_debug_get_source_file (mono_class_get_image (mono_method_get_class (method)), sequencePoint->sourceFileIndex)->file, sequencePoint->lineStart, sequencePoint->columnStart, sequencePoint->lineEnd, sequencePoint->columnEnd); buffer_add_int(buf, sequencePoint->ilOffset); buffer_add_int(buf, sequencePoint->lineStart); @@ -10588,12 +10588,13 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g buffer_add_typeid(buf, domain, mono_class_from_mono_type(il2cpp_type_inflate (il2cpp_get_type_from_index(executionContextInfo[i].typeIndex), il2cpp_mono_method_get_context(method)))); for (i = 0; i < executionInfoCount; i++) - buffer_add_string(buf, g_il2cpp_metadata->methodExecutionContextInfoStrings[executionContextInfo[i].nameIndex]); + buffer_add_string(buf, il2cpp_debug_get_local_name (mono_class_get_image (mono_method_get_class (method)), executionContextInfo[i].nameIndex)); for (i = 0; i < executionInfoCount; i++) { - buffer_add_int(buf, g_il2cpp_metadata->methodScopes[executionContextInfo[i].scopeIndex].startOffset); - buffer_add_int(buf, g_il2cpp_metadata->methodScopes[executionContextInfo[i].scopeIndex].endOffset); + Il2CppMethodScope* scope = il2cpp_debug_get_local_scope (mono_class_get_image (mono_method_get_class (method)), executionContextInfo[i].scopeIndex); + buffer_add_int(buf, scope->startOffset); + buffer_add_int(buf, scope->endOffset); } #endif // !RUNTIME_IL2CPP break; @@ -12308,11 +12309,11 @@ unity_process_breakpoint_inner(DebuggerTlsData *tls, gboolean from_signal, Il2Cp * resume. */ if (ss_events) - process_event(EVENT_KIND_STEP, method, 0, ctx, ss_events, suspend_policy, sequencePoint->id); + process_event(EVENT_KIND_STEP, method, 0, ctx, ss_events, suspend_policy, sequencePoint); if (bp_events) - process_event(kind, method, 0, ctx, bp_events, suspend_policy, sequencePoint->id); + process_event(kind, method, 0, ctx, bp_events, suspend_policy, sequencePoint); if (enter_leave_events) - process_event(kind, method, 0, ctx, enter_leave_events, suspend_policy, sequencePoint->id); + process_event(kind, method, 0, ctx, enter_leave_events, suspend_policy, sequencePoint); } void diff --git a/mono/mini/debugger-agent.h b/mono/mini/debugger-agent.h index 581579c21c82..587d5b7a7771 100644 --- a/mono/mini/debugger-agent.h +++ b/mono/mini/debugger-agent.h @@ -33,7 +33,7 @@ void #ifndef RUNTIME_IL2CPP debugger_agent_single_step_from_context (MonoContext *ctx); #else -debugger_agent_single_step_from_context (MonoContext *ctx, int sequencePointId); +debugger_agent_single_step_from_context (MonoContext *ctx, Il2CppSequencePoint* sequencePoint); #endif void diff --git a/mono/mini/il2cpp-compat.h b/mono/mini/il2cpp-compat.h index e034dd416c21..aeca88b5d8e7 100644 --- a/mono/mini/il2cpp-compat.h +++ b/mono/mini/il2cpp-compat.h @@ -446,7 +446,6 @@ void il2cpp_mono_error_cleanup (MonoError *oerror); MonoException* il2cpp_mono_error_convert_to_exception (MonoError *target_error); const char* il2cpp_mono_error_get_message (MonoError *oerror); void il2cpp_mono_error_assert_ok_pos (MonoError *error, const char* filename, int lineno); -Il2CppSequencePoint* il2cpp_get_sequence_points(void* *iter); Il2CppSequencePoint* il2cpp_get_method_sequence_points(MonoMethod* method, void* *iter); MonoClass* il2cpp_class_get_nested_types_accepts_generic(MonoClass *monoClass, void* *iter); MonoClass* il2cpp_defaults_object_class(); @@ -469,7 +468,7 @@ MonoGenericInst* il2cpp_method_get_generic_class_inst(MonoMethodInflated *imetho MonoClass* il2cpp_generic_class_get_container_class(MonoGenericClass *gclass); void il2cpp_mono_thread_detach(MonoThread* thread); MonoClass* il2cpp_mono_get_string_class (void); -Il2CppSequencePoint* il2cpp_get_sequence_point(int id); +Il2CppSequencePoint* il2cpp_get_sequence_point(MonoImage* image, int id); char* il2cpp_assembly_get_full_name(MonoAssembly *assembly); const MonoMethod* il2cpp_get_seq_point_method(Il2CppSequencePoint *seqPoint); const MonoClass* il2cpp_get_class_from_index(int index); @@ -485,4 +484,7 @@ MonoGenericClass* il2cpp_m_type_get_generic_class(MonoType* type); const MonoAssembly* il2cpp_m_method_get_assembly(MonoMethod* method); const MonoAssembly* il2cpp_m_domain_get_corlib (MonoDomain *domain); mono_bool il2cpp_m_class_is_initialized (MonoClass* klass); +Il2CppSequencePointSourceFile* il2cpp_debug_get_source_file(MonoImage* image, int index); +const char* il2cpp_debug_get_local_name(MonoImage* image, int index); +Il2CppMethodScope* il2cpp_debug_get_local_scope(MonoImage* image, int index); #endif // RUNTIME_IL2CPP diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 083d34ca656b..41ebae0e6d0b 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -1272,22 +1272,13 @@ const char* il2cpp_domain_get_name(MonoDomain* domain) return ((Il2CppDomain*)domain)->friendly_name; } -Il2CppSequencePoint* il2cpp_get_sequence_points(void* *iter) -{ -#if IL2CPP_MONO_DEBUGGER - return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints(iter); -#else - return NULL; -#endif -} - Il2CppSequencePoint* il2cpp_get_method_sequence_points(MonoMethod* method, void* *iter) { #if IL2CPP_MONO_DEBUGGER - if (!method) - return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints(iter); - else - return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints((const MethodInfo*)method, iter); + if (method == NULL) + return il2cpp::utils::Debugger::GetAllSequencePoints (iter); + else + return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints((const MethodInfo*)method, iter); #else return NULL; #endif @@ -1477,10 +1468,10 @@ MonoClass* il2cpp_mono_get_string_class (void) return (MonoClass*)il2cpp_defaults.string_class; } -Il2CppSequencePoint* il2cpp_get_sequence_point(int id) +Il2CppSequencePoint* il2cpp_get_sequence_point(MonoImage* image, int id) { #if IL2CPP_MONO_DEBUGGER - return il2cpp::utils::Debugger::GetSequencePoint(id); + return il2cpp::utils::Debugger::GetSequencePoint(image, id); #else return NULL; #endif @@ -1565,5 +1556,20 @@ MonoType* il2cpp_mono_class_get_byref_type (MonoClass *klass) return (MonoType*)il2cpp::vm::Class::GetByrefType((Il2CppClass*)klass); } +Il2CppSequencePointSourceFile* il2cpp_debug_get_source_file(MonoImage* image, int index) +{ + return ((Il2CppImage*)image)->codeGenModule->debuggerMetadata->sequencePointSourceFiles + index; +} + +const char* il2cpp_debug_get_local_name(MonoImage* image, int index) +{ + return ((Il2CppImage*)image)->codeGenModule->debuggerMetadata->methodExecutionContextInfoStrings[index]; +} + +Il2CppMethodScope* il2cpp_debug_get_local_scope(MonoImage* image, int index) +{ + return ((Il2CppImage*)image)->codeGenModule->debuggerMetadata->methodScopes + index; +} + } #endif // RUNTIME_IL2CPP From f60719b9faac0d512d36fe774f1fda54dd6dcb52 Mon Sep 17 00:00:00 2001 From: Michael DeRoy Date: Mon, 10 Dec 2018 15:28:25 -0500 Subject: [PATCH 17/23] Remove the and headers from being included in codegen --- mono/mini/il2cpp-stubs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mono/mini/il2cpp-stubs.cpp b/mono/mini/il2cpp-stubs.cpp index 41ebae0e6d0b..fdeccced6c2f 100644 --- a/mono/mini/il2cpp-stubs.cpp +++ b/mono/mini/il2cpp-stubs.cpp @@ -27,6 +27,7 @@ #include "vm/Runtime.h" #include "vm/String.h" #include "vm-utils/Debugger.h" +#include "os/Thread.h" #include #include From 44ce5b79e20bee3a9087cd47317c33f12e4283bc Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Wed, 12 Dec 2018 10:49:35 -0500 Subject: [PATCH 18/23] Rename UNITY_TINY defines to IL2CPP_TINY Defines in the IL2CPP code should not be named for UNITY, as we want IL2CPP to work independently. Clean up the names of the `UNITY_TINY` defines then by renaming them. This change should have no impact on runtime behavior or code size. --- mono/mini/debugger-agent.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index c5d843069972..223df8530c63 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -5401,7 +5401,7 @@ static MonoMethod* notify_debugger_of_wait_completion_method_cache = NULL; static MonoMethod* get_notify_debugger_of_wait_completion_method (void) { -#if UNITY_TINY +#if IL2CPP_TINY return NULL; #else if (notify_debugger_of_wait_completion_method_cache != NULL) @@ -5414,7 +5414,7 @@ get_notify_debugger_of_wait_completion_method (void) notify_debugger_of_wait_completion_method_cache = (MonoMethod *)g_ptr_array_index (array, 0); g_ptr_array_free (array, TRUE); return notify_debugger_of_wait_completion_method_cache; -#endif // UNITY_TINY +#endif // IL2CPP_TINY } #ifndef RUNTIME_IL2CPP From 0e2663d755f70c3692634407a9b81c4817576865 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Fri, 14 Dec 2018 09:13:41 -0500 Subject: [PATCH 19/23] Don't attempt to stop threads on exit With IL2CPP, we don't have a good way to stop managed threads. So let's just ignore that and exit the process. This won't clean up and run finalizers, but the process it ending anyway, so we don't care too much. --- mono/mini/debugger-agent.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 223df8530c63..55a39e4de025 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -8753,12 +8753,20 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf) mono_environment_exitcode_set (exit_code); + /* + * We don't have a good way to suspend threads in IL2CPP, so just + * skip this code and call exit below. We will not shut down cleanly + * (e.g. run finalizers) but we don't care too much about that with + * IL2CPP. + */ +#ifndef RUNTIME_IL2CPP /* Suspend all managed threads since the runtime is going away */ DEBUG_PRINTF (1, "Suspending all threads...\n"); mono_thread_suspend_all_other_threads (); DEBUG_PRINTF (1, "Shutting down the runtime...\n"); mono_runtime_quit (); transport_close2 (); +#endif DEBUG_PRINTF (1, "Exiting...\n"); exit (exit_code); From c39d8e93c316e8a4f42b7c71440662287c718f9d Mon Sep 17 00:00:00 2001 From: Jonas Echterhoff Date: Tue, 4 Dec 2018 14:45:50 +0100 Subject: [PATCH 20/23] cache pause point active state --- mono/mini/debugger-agent.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 55a39e4de025..8a7ea47a6af3 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -741,6 +741,8 @@ static SingleStepReq *ss_req; static int ss_count; #endif +bool g_unity_pause_point_active; + /* The protocol version of the client */ static int major_version, minor_version; @@ -1165,13 +1167,27 @@ void mono_debugger_install_sequence_point_check(volatile uint32_t* check) g_unity_check = check; } +gboolean unity_debugger_agent_is_global_breakpoint_active() +{ + if (!ss_req) + return FALSE; + else + return ss_req->global; +} + +int32_t unity_debugger_agent_is_single_stepping () +{ + return ss_count; +} + #define INC_PAUSE_COUNT() do { mono_atomic_inc_i32 (g_unity_check); } while (0) #define DEC_PAUSE_COUNT() do { mono_atomic_dec_i32 (g_unity_check); } while (0) - +#define UPDATE_PAUSE_STATE() do { g_unity_pause_point_active = unity_debugger_agent_is_global_breakpoint_active() || unity_debugger_agent_is_single_stepping(); } while (0) #else #define INC_PAUSE_COUNT() #define DEC_PAUSE_COUNT() +#define UPDATE_PAUSE_STATE() #endif // RUNTIME_IL2CPP @@ -6014,6 +6030,7 @@ start_single_stepping (void) { #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED int val = mono_atomic_inc_i32 (&ss_count); + UPDATE_PAUSE_STATE(); INC_PAUSE_COUNT(); if (val == 1) { @@ -6032,6 +6049,7 @@ stop_single_stepping (void) { #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED int val = mono_atomic_dec_i32 (&ss_count); + UPDATE_PAUSE_STATE(); DEC_PAUSE_COUNT(); if (val == 0) { @@ -6068,6 +6086,7 @@ ss_stop (SingleStepReq *ss_req) if (ss_req->global) { stop_single_stepping (); ss_req->global = FALSE; + UPDATE_PAUSE_STATE(); } } @@ -6435,6 +6454,7 @@ ss_start (SingleStepReq *ss_req, MonoMethod *method, SeqPoint* sp, MonoSeqPointI } else { ss_req->global = FALSE; } + UPDATE_PAUSE_STATE(); if (ss_req_bp_cache) g_hash_table_destroy (ss_req_bp_cache); @@ -6508,6 +6528,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint { ss_req->global = FALSE; } + UPDATE_PAUSE_STATE(); } #endif // RUNTIME_IL2CPP @@ -12342,17 +12363,9 @@ unity_debugger_agent_breakpoint(Il2CppSequencePoint* sequencePoint) unity_process_breakpoint_inner(tls, FALSE, sequencePoint); } -gboolean unity_debugger_agent_is_global_breakpoint_active() -{ - if (!ss_req) - return FALSE; - else - return ss_req->global; -} - -int32_t unity_debugger_agent_is_single_stepping () +gboolean unity_pause_point_active() { - return ss_count; + return unity_debugger_agent_is_global_breakpoint_active() || unity_debugger_agent_is_single_stepping(); } gboolean unity_sequence_point_active(Il2CppSequencePoint *seqPoint) From a782c271b09d453adfcd49e1c4a12d9577f241ff Mon Sep 17 00:00:00 2001 From: Jonas Echterhoff Date: Tue, 4 Dec 2018 14:55:56 +0100 Subject: [PATCH 21/23] Inline Sequence Point checks; hard code sequence point reference into macro invocation instead of looking up from index; hard code sequence point type into macro invocation --- mono/mini/debugger-agent.c | 51 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 8a7ea47a6af3..6f6aec0aabac 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -3458,7 +3458,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls) } else if (tls->il2cpp_context->frameCount > 0) { for (int frame_index = tls->il2cpp_context->frameCount - 1; frame_index >= 0; --frame_index) { - Il2CppSequencePoint* seq_point = il2cpp_get_sequence_point (tls->il2cpp_context->executionContexts[frame_index]->currentSequencePoint); + Il2CppSequencePoint* seq_point = tls->il2cpp_context->executionContexts[frame_index]->currentSequencePoint; StackFrame* frame = g_new0(StackFrame, 1); MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point); frame->method = sp_method; @@ -5886,7 +5886,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, Il2CppSeq #ifndef RUNTIME_IL2CPP process_event (EVENT_KIND_STEP, jinfo_get_method (ji), il_offset, ctx, events, suspend_policy); #else - Il2CppSequencePoint* sequence_pt = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint); + Il2CppSequencePoint* sequence_pt = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint; MonoMethod *sp_method = il2cpp_get_seq_point_method(sequence_pt); /* @@ -6481,7 +6481,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint } else { if (ss_req->depth == STEP_DEPTH_OVER) { - MonoMethod* currentMethod = il2cpp_get_seq_point_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint)); + MonoMethod* currentMethod = il2cpp_get_seq_point_method(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint); void *seqPointIter = NULL; Il2CppSequencePoint *seqPoint; @@ -6497,7 +6497,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint if (tls->il2cpp_context->frameCount > 1) { - Il2CppSequencePoint* sequencePointForStepOut = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 2]->currentSequencePoint); + Il2CppSequencePoint* sequencePointForStepOut = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 2]->currentSequencePoint; g_assert(sequencePointForStepOut->kind == kSequencePointKind_StepOut); ss_bp_add_one_il2cpp(ss_req, &ss_req_bp_count, &ss_req_bp_cache, sequencePointForStepOut); } @@ -6593,7 +6593,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte if (tls->il2cpp_context->frameCount > 0) { - Il2CppSequencePoint* seq_point = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint); + Il2CppSequencePoint* seq_point = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint; MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point); ss_req->start_method = sp_method; ss_req->last_method = sp_method; @@ -6829,7 +6829,7 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point(DebuggerTlsData *tl int frameIndex = tls->il2cpp_context->frameCount - 1; while (frameIndex >= 0) { - Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint), tls->exception); + Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, tls->exception); if (sp) return sp; @@ -6853,7 +6853,7 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point_from_exeption(Debug int frameIndex = tls->il2cpp_context->frameCount - 1; while (frameIndex >= 0) { - sp = il2cpp_find_catch_sequence_point_in_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint), exc); + sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, exc); if (sp) return sp; @@ -12363,27 +12363,48 @@ unity_debugger_agent_breakpoint(Il2CppSequencePoint* sequencePoint) unity_process_breakpoint_inner(tls, FALSE, sequencePoint); } +void unity_debugger_agent_pausepoint() +{ + if (is_debugger_thread()) + return; + + save_thread_context(NULL); + suspend_current(); +} + gboolean unity_pause_point_active() { - return unity_debugger_agent_is_global_breakpoint_active() || unity_debugger_agent_is_single_stepping(); + return unity_debugger_agent_is_global_breakpoint_active() || unity_debugger_agent_is_single_stepping(); } -gboolean unity_sequence_point_active(Il2CppSequencePoint *seqPoint) +gboolean unity_sequence_point_active_entry(Il2CppSequencePoint *seqPoint) { - gboolean global = unity_debugger_agent_is_global_breakpoint_active(); + int i = 0; + while (i < event_requests->len) + { + EventRequest *req = (EventRequest *)g_ptr_array_index (event_requests, i); - if ((seqPoint->ilOffset != METHOD_ENTRY_IL_OFFSET) && (seqPoint->ilOffset != METHOD_EXIT_IL_OFFSET)) - return seqPoint->isActive || global || unity_debugger_agent_is_single_stepping (); + if (req->event_kind == EVENT_KIND_METHOD_ENTRY) + { + return seqPoint->isActive || g_unity_pause_point_active; + } + + ++i; + } + return FALSE; +} + +gboolean unity_sequence_point_active_exit(Il2CppSequencePoint *seqPoint) +{ int i = 0; while (i < event_requests->len) { EventRequest *req = (EventRequest *)g_ptr_array_index (event_requests, i); - if ((req->event_kind == EVENT_KIND_METHOD_ENTRY && seqPoint->ilOffset == METHOD_ENTRY_IL_OFFSET) || - (req->event_kind == EVENT_KIND_METHOD_EXIT && seqPoint->ilOffset == METHOD_EXIT_IL_OFFSET)) + if (req->event_kind == EVENT_KIND_METHOD_EXIT) { - return seqPoint->isActive || global || unity_debugger_agent_is_single_stepping (); + return seqPoint->isActive || g_unity_pause_point_active; } ++i; From 0299a6b872dcbf471f6d10fb58f9e159de30a862 Mon Sep 17 00:00:00 2001 From: Jonas Echterhoff Date: Mon, 17 Dec 2018 14:49:07 +0100 Subject: [PATCH 22/23] Remove no longer needed debugger check code --- mono/mini/debugger-agent.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 6f6aec0aabac..47bff77d9e08 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -1161,12 +1161,6 @@ void mono_debugger_install_runtime_callbacks(MonoDebuggerRuntimeCallbacks* cbs) callbacks = *cbs; } -uint32_t* g_unity_check; -void mono_debugger_install_sequence_point_check(volatile uint32_t* check) -{ - g_unity_check = check; -} - gboolean unity_debugger_agent_is_global_breakpoint_active() { if (!ss_req) @@ -1180,13 +1174,9 @@ int32_t unity_debugger_agent_is_single_stepping () return ss_count; } -#define INC_PAUSE_COUNT() do { mono_atomic_inc_i32 (g_unity_check); } while (0) -#define DEC_PAUSE_COUNT() do { mono_atomic_dec_i32 (g_unity_check); } while (0) #define UPDATE_PAUSE_STATE() do { g_unity_pause_point_active = unity_debugger_agent_is_global_breakpoint_active() || unity_debugger_agent_is_single_stepping(); } while (0) #else -#define INC_PAUSE_COUNT() -#define DEC_PAUSE_COUNT() #define UPDATE_PAUSE_STATE() #endif // RUNTIME_IL2CPP @@ -4864,7 +4854,6 @@ set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, MonoError inst->seq_point = seqPoint; seqPoint->isActive++; - INC_PAUSE_COUNT(); mono_loader_lock(); g_ptr_array_add(bp->children, inst); @@ -4954,7 +4943,6 @@ static MonoBreakpoint* set_breakpoint_fast(Il2CppSequencePoint *sp, EventRequest inst->seq_point = sp; sp->isActive++; - INC_PAUSE_COUNT(); mono_loader_lock(); g_ptr_array_add(bp->children, inst); @@ -4991,7 +4979,6 @@ clear_breakpoint (MonoBreakpoint *bp) remove_breakpoint(inst); #else inst->seq_point->isActive--; - DEC_PAUSE_COUNT(); #endif g_free (inst); @@ -5069,7 +5056,6 @@ clear_breakpoints_for_domain (MonoDomain *domain) remove_breakpoint (inst); #else inst->seq_point->isActive--; - DEC_PAUSE_COUNT(); #endif g_free (inst); @@ -6031,7 +6017,6 @@ start_single_stepping (void) #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED int val = mono_atomic_inc_i32 (&ss_count); UPDATE_PAUSE_STATE(); - INC_PAUSE_COUNT(); if (val == 1) { mono_arch_start_single_stepping (); @@ -6050,7 +6035,6 @@ stop_single_stepping (void) #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED int val = mono_atomic_dec_i32 (&ss_count); UPDATE_PAUSE_STATE(); - DEC_PAUSE_COUNT(); if (val == 0) { mono_arch_stop_single_stepping (); @@ -6567,7 +6551,6 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte DEBUG_PRINTF (1, "[dbg] Starting single step of thread %p (depth=%s).\n", thread, ss_depth_to_string (depth)); ss_req = g_new0 (SingleStepReq, 1); - INC_PAUSE_COUNT(); ss_req->req = req; ss_req->thread = thread; ss_req->size = size; @@ -6709,7 +6692,6 @@ ss_destroy (SingleStepReq *req) ss_stop (ss_req); g_free (ss_req); - DEC_PAUSE_COUNT(); ss_req = NULL; } From 46ed83ea2e0a412b45ff742488e23f6601a3f0d0 Mon Sep 17 00:00:00 2001 From: Jonathan Chambers Date: Wed, 2 Jan 2019 14:55:42 -0500 Subject: [PATCH 23/23] Use gboolean rather than C++ bool type in Mono C code. --- mono/mini/debugger-agent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 47bff77d9e08..024896cec61f 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -741,7 +741,7 @@ static SingleStepReq *ss_req; static int ss_count; #endif -bool g_unity_pause_point_active; +gboolean g_unity_pause_point_active; /* The protocol version of the client */ static int major_version, minor_version;