Skip to content

Commit 2188d96

Browse files
committed
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
1 parent 359132d commit 2188d96

File tree

4 files changed

+57
-48
lines changed

4 files changed

+57
-48
lines changed

mono/mini/debugger-agent.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
#ifdef RUNTIME_IL2CPP
123123
extern Il2CppMonoDefaults il2cpp_mono_defaults;
124124
extern Il2CppMonoDebugOptions il2cpp_mono_debug_options;
125-
const Il2CppDebuggerMetadataRegistration *g_il2cpp_metadata;
126125
#endif
127126

128127

@@ -2300,10 +2299,9 @@ static GPtrArray *ids [ID_NUM];
23002299

23012300
static GHashTable* s_jit_info_hashtable;
23022301

2303-
void mono_debugger_il2cpp_init (const Il2CppDebuggerMetadataRegistration *data)
2302+
void mono_debugger_il2cpp_init ()
23042303
{
23052304
s_jit_info_hashtable = g_hash_table_new_full(mono_aligned_addr_hash, NULL, NULL, NULL);
2306-
g_il2cpp_metadata = data;
23072305
debug_options.native_debugger_break = FALSE;
23082306
}
23092307

@@ -3882,7 +3880,7 @@ static void
38823880
#ifndef RUNTIME_IL2CPP
38833881
process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx, GSList *events, int suspend_policy)
38843882
#else
3885-
process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx, GSList *events, int suspend_policy, uint64_t il2cpp_seqpoint_id)
3883+
process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx, GSList *events, int suspend_policy, Il2CppSequencePoint* sequencePoint)
38863884
#endif
38873885
{
38883886
Buffer buf;
@@ -3973,7 +3971,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
39733971
case EVENT_KIND_METHOD_EXIT:
39743972
buffer_add_methodid (&buf, domain, (MonoMethod *)arg);
39753973
#if defined(RUNTIME_IL2CPP) && defined(IL2CPP_DEBUGGER_TESTS)
3976-
buffer_add_long (&buf, il2cpp_seqpoint_id);
3974+
buffer_add_long (&buf, sequencePoint->id);
39773975
#endif
39783976
break;
39793977
case EVENT_KIND_ASSEMBLY_LOAD:
@@ -3998,7 +3996,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
39983996
buffer_add_methodid (&buf, domain, (MonoMethod *)arg);
39993997
buffer_add_long (&buf, il_offset);
40003998
#if defined(RUNTIME_IL2CPP) && defined(IL2CPP_DEBUGGER_TESTS)
4001-
buffer_add_long (&buf, il2cpp_seqpoint_id);
3999+
buffer_add_long (&buf, sequencePoint->id);
40024000
#endif
40034001
break;
40044002
case EVENT_KIND_VM_START:
@@ -4012,7 +4010,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
40124010
DebuggerEventInfo *ei = (DebuggerEventInfo *)arg;
40134011
buffer_add_objid (&buf, ei->exc);
40144012
#if defined(RUNTIME_IL2CPP) && defined(IL2CPP_DEBUGGER_TESTS)
4015-
buffer_add_long(&buf, il2cpp_seqpoint_id);
4013+
buffer_add_long(&buf, sequencePoint->id);
40164014
#endif
40174015
/*
40184016
* 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)
41174115
#ifndef RUNTIME_IL2CPP
41184116
process_event (event, arg, 0, NULL, events, suspend_policy);
41194117
#else
4120-
process_event (event, arg, 0, NULL, events, suspend_policy, 0);
4118+
process_event (event, arg, 0, NULL, events, suspend_policy, NULL);
41214119
#endif
41224120
}
41234121

@@ -5719,7 +5717,7 @@ mono_debugger_agent_user_break (void)
57195717
#ifndef RUNTIME_IL2CPP
57205718
process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy);
57215719
#else
5722-
process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy, 0);
5720+
process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy, NULL);
57235721
#endif
57245722
} else if (debug_options.native_debugger_break) {
57255723
G_BREAKPOINT ();
@@ -5746,7 +5744,7 @@ static void
57465744
#ifndef RUNTIME_IL2CPP
57475745
process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal)
57485746
#else
5749-
process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int sequencePointId)
5747+
process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, Il2CppSequencePoint* sequencePoint)
57505748
#endif
57515749
{
57525750
MonoJitInfo *ji;
@@ -5862,7 +5860,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int seque
58625860
#ifndef RUNTIME_IL2CPP
58635861
events = create_event_list (EVENT_KIND_STEP, reqs, ji, NULL, &suspend_policy);
58645862
#else
5865-
events = create_event_list(EVENT_KIND_STEP, reqs, il2cpp_get_sequence_point(sequencePointId), NULL, &suspend_policy);
5863+
events = create_event_list(EVENT_KIND_STEP, reqs, sequencePoint, NULL, &suspend_policy);
58665864
#endif
58675865

58685866
g_ptr_array_free (reqs, TRUE);
@@ -5898,7 +5896,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int seque
58985896
if(!ss_update_il2cpp(ss_req,tls,ctx,sequence_pt))
58995897
return;
59005898

5901-
process_event(EVENT_KIND_STEP, sp_method, sequence_pt->ilOffset, NULL, events, suspend_policy, sequencePointId);
5899+
process_event(EVENT_KIND_STEP, sp_method, sequence_pt->ilOffset, NULL, events, suspend_policy, sequencePoint);
59025900
#endif
59035901
}
59045902

@@ -5943,7 +5941,7 @@ void
59435941
#ifndef RUNTIME_IL2CPP
59445942
debugger_agent_single_step_from_context (MonoContext *ctx)
59455943
#else
5946-
debugger_agent_single_step_from_context (MonoContext *ctx, int sequencePointId)
5944+
debugger_agent_single_step_from_context (MonoContext *ctx, Il2CppSequencePoint* sequencePoint)
59475945
#endif
59485946
{
59495947
DebuggerTlsData *tls;
@@ -5972,7 +5970,7 @@ debugger_agent_single_step_from_context (MonoContext *ctx, int sequencePointId)
59725970
#else
59735971
save_thread_context(NULL);
59745972

5975-
process_single_step_inner(tls, FALSE, sequencePointId);
5973+
process_single_step_inner(tls, FALSE, sequencePoint);
59765974
#endif
59775975
}
59785976

@@ -6745,7 +6743,7 @@ mono_debugger_agent_debug_log (int level, MonoString *category, MonoString *mess
67456743
#ifndef RUNTIME_IL2CPP
67466744
process_event (EVENT_KIND_USER_LOG, &ei, 0, NULL, events, suspend_policy);
67476745
#else
6748-
process_event (EVENT_KIND_USER_LOG, &ei, 0, NULL, events, suspend_policy, 0);
6746+
process_event (EVENT_KIND_USER_LOG, &ei, 0, NULL, events, suspend_policy, NULL);
67496747
#endif
67506748

67516749
g_free (ei.category);
@@ -6780,7 +6778,7 @@ mono_debugger_agent_unhandled_exception (MonoException *exc)
67806778
#ifndef RUNTIME_IL2CPP
67816779
process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy);
67826780
#else
6783-
process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, 0);
6781+
process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, NULL);
67846782
#endif
67856783
}
67866784
#endif
@@ -6930,7 +6928,7 @@ unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *s
69306928
}
69316929
}
69326930

6933-
process_event(EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, sequencePoint ? sequencePoint->id : 0);
6931+
process_event(EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy, sequencePoint);
69346932

69356933
if (tls)
69366934
tls->exception = NULL;
@@ -6975,7 +6973,7 @@ mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx
69756973
#ifndef RUNTIME_IL2CPP
69766974
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL);
69776975
#else
6978-
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, 0);
6976+
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, NULL);
69796977
#endif
69806978
return;
69816979
}
@@ -7004,7 +7002,7 @@ mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx
70047002
#ifndef RUNTIME_IL2CPP
70057003
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL);
70067004
#else
7007-
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, 0);
7005+
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, SUSPEND_POLICY_ALL, NULL);
70087006
#endif
70097007
return;
70107008
}
@@ -7064,7 +7062,7 @@ mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx
70647062
#ifndef RUNTIME_IL2CPP
70657063
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, suspend_policy);
70667064
#else
7067-
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, suspend_policy, 0);
7065+
process_event (EVENT_KIND_EXCEPTION, &ei, 0, throw_ctx, events, suspend_policy, NULL);
70687066
#endif
70697067

70707068
if (tls)
@@ -10404,15 +10402,17 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
1040410402
buffer_add_int(buf, uniqueFileSequencePoints->len);
1040510403
for (i = 0; i < uniqueFileSequencePoints->len; ++i) {
1040610404
Il2CppSequencePoint* sequencePoint = g_ptr_array_index(uniqueFileSequencePoints, i);
10407-
buffer_add_string(buf, g_il2cpp_metadata->sequencePointSourceFiles[sequencePoint->sourceFileIndex].file);
10405+
Il2CppSequencePointSourceFile* sourceFile = il2cpp_debug_get_source_file (mono_class_get_image (mono_method_get_class (method)), sequencePoint->sourceFileIndex);
10406+
buffer_add_string(buf, sourceFile->file);
1040810407
if (CHECK_PROTOCOL_VERSION(2, 14)) {
10409-
buffer_add_data(buf, g_il2cpp_metadata->sequencePointSourceFiles[sequencePoint->sourceFileIndex].hash, 16);
10408+
buffer_add_data(buf, sourceFile->hash, 16);
1041010409
}
1041110410
}
1041210411
}
1041310412
else {
1041410413
if (uniqueFileSequencePoints->len > 0) {
10415-
buffer_add_string(buf, g_il2cpp_metadata->sequencePointSourceFiles[((Il2CppSequencePoint*)g_ptr_array_index(uniqueFileSequencePoints, 0))->sourceFileIndex].file);
10414+
Il2CppSequencePointSourceFile* sourceFile = il2cpp_debug_get_source_file (mono_class_get_image (mono_method_get_class (method)), ((Il2CppSequencePoint*)g_ptr_array_index(uniqueFileSequencePoints, 0))->sourceFileIndex);
10415+
buffer_add_string(buf, sourceFile->file);
1041610416
} else {
1041710417
buffer_add_string(buf, "");
1041810418
}
@@ -10436,7 +10436,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
1043610436
if (sequencePoint->kind == kSequencePointKind_StepOut)
1043710437
continue;
1043810438

10439-
DEBUG_PRINTF(10, "IL%x -> %s:%d %d %d %d\n", sequencePoint->ilOffset, g_il2cpp_metadata->sequencePointSourceFiles[sequencePoint->sourceFileIndex],
10439+
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,
1044010440
sequencePoint->lineStart, sequencePoint->columnStart, sequencePoint->lineEnd, sequencePoint->columnEnd);
1044110441
buffer_add_int(buf, sequencePoint->ilOffset);
1044210442
buffer_add_int(buf, sequencePoint->lineStart);
@@ -10588,12 +10588,13 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
1058810588
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))));
1058910589

1059010590
for (i = 0; i < executionInfoCount; i++)
10591-
buffer_add_string(buf, g_il2cpp_metadata->methodExecutionContextInfoStrings[executionContextInfo[i].nameIndex]);
10591+
buffer_add_string(buf, il2cpp_debug_get_local_name (mono_class_get_image (mono_method_get_class (method)), executionContextInfo[i].nameIndex));
1059210592

1059310593
for (i = 0; i < executionInfoCount; i++)
1059410594
{
10595-
buffer_add_int(buf, g_il2cpp_metadata->methodScopes[executionContextInfo[i].scopeIndex].startOffset);
10596-
buffer_add_int(buf, g_il2cpp_metadata->methodScopes[executionContextInfo[i].scopeIndex].endOffset);
10595+
Il2CppMethodScope* scope = il2cpp_debug_get_local_scope (mono_class_get_image (mono_method_get_class (method)), executionContextInfo[i].scopeIndex);
10596+
buffer_add_int(buf, scope->startOffset);
10597+
buffer_add_int(buf, scope->endOffset);
1059710598
}
1059810599
#endif // !RUNTIME_IL2CPP
1059910600
break;
@@ -12308,11 +12309,11 @@ unity_process_breakpoint_inner(DebuggerTlsData *tls, gboolean from_signal, Il2Cp
1230812309
* resume.
1230912310
*/
1231012311
if (ss_events)
12311-
process_event(EVENT_KIND_STEP, method, 0, ctx, ss_events, suspend_policy, sequencePoint->id);
12312+
process_event(EVENT_KIND_STEP, method, 0, ctx, ss_events, suspend_policy, sequencePoint);
1231212313
if (bp_events)
12313-
process_event(kind, method, 0, ctx, bp_events, suspend_policy, sequencePoint->id);
12314+
process_event(kind, method, 0, ctx, bp_events, suspend_policy, sequencePoint);
1231412315
if (enter_leave_events)
12315-
process_event(kind, method, 0, ctx, enter_leave_events, suspend_policy, sequencePoint->id);
12316+
process_event(kind, method, 0, ctx, enter_leave_events, suspend_policy, sequencePoint);
1231612317
}
1231712318

1231812319
void

mono/mini/debugger-agent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void
3333
#ifndef RUNTIME_IL2CPP
3434
debugger_agent_single_step_from_context (MonoContext *ctx);
3535
#else
36-
debugger_agent_single_step_from_context (MonoContext *ctx, int sequencePointId);
36+
debugger_agent_single_step_from_context (MonoContext *ctx, Il2CppSequencePoint* sequencePoint);
3737
#endif
3838

3939
void

mono/mini/il2cpp-compat.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ void il2cpp_mono_error_cleanup (MonoError *oerror);
446446
MonoException* il2cpp_mono_error_convert_to_exception (MonoError *target_error);
447447
const char* il2cpp_mono_error_get_message (MonoError *oerror);
448448
void il2cpp_mono_error_assert_ok_pos (MonoError *error, const char* filename, int lineno);
449-
Il2CppSequencePoint* il2cpp_get_sequence_points(void* *iter);
450449
Il2CppSequencePoint* il2cpp_get_method_sequence_points(MonoMethod* method, void* *iter);
451450
MonoClass* il2cpp_class_get_nested_types_accepts_generic(MonoClass *monoClass, void* *iter);
452451
MonoClass* il2cpp_defaults_object_class();
@@ -469,7 +468,7 @@ MonoGenericInst* il2cpp_method_get_generic_class_inst(MonoMethodInflated *imetho
469468
MonoClass* il2cpp_generic_class_get_container_class(MonoGenericClass *gclass);
470469
void il2cpp_mono_thread_detach(MonoThread* thread);
471470
MonoClass* il2cpp_mono_get_string_class (void);
472-
Il2CppSequencePoint* il2cpp_get_sequence_point(int id);
471+
Il2CppSequencePoint* il2cpp_get_sequence_point(MonoImage* image, int id);
473472
char* il2cpp_assembly_get_full_name(MonoAssembly *assembly);
474473
const MonoMethod* il2cpp_get_seq_point_method(Il2CppSequencePoint *seqPoint);
475474
const MonoClass* il2cpp_get_class_from_index(int index);
@@ -485,4 +484,7 @@ MonoGenericClass* il2cpp_m_type_get_generic_class(MonoType* type);
485484
const MonoAssembly* il2cpp_m_method_get_assembly(MonoMethod* method);
486485
const MonoAssembly* il2cpp_m_domain_get_corlib (MonoDomain *domain);
487486
mono_bool il2cpp_m_class_is_initialized (MonoClass* klass);
487+
Il2CppSequencePointSourceFile* il2cpp_debug_get_source_file(MonoImage* image, int index);
488+
const char* il2cpp_debug_get_local_name(MonoImage* image, int index);
489+
Il2CppMethodScope* il2cpp_debug_get_local_scope(MonoImage* image, int index);
488490
#endif // RUNTIME_IL2CPP

mono/mini/il2cpp-stubs.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,22 +1272,13 @@ const char* il2cpp_domain_get_name(MonoDomain* domain)
12721272
return ((Il2CppDomain*)domain)->friendly_name;
12731273
}
12741274

1275-
Il2CppSequencePoint* il2cpp_get_sequence_points(void* *iter)
1276-
{
1277-
#if IL2CPP_MONO_DEBUGGER
1278-
return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints(iter);
1279-
#else
1280-
return NULL;
1281-
#endif
1282-
}
1283-
12841275
Il2CppSequencePoint* il2cpp_get_method_sequence_points(MonoMethod* method, void* *iter)
12851276
{
12861277
#if IL2CPP_MONO_DEBUGGER
1287-
if (!method)
1288-
return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints(iter);
1289-
else
1290-
return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints((const MethodInfo*)method, iter);
1278+
if (method == NULL)
1279+
return il2cpp::utils::Debugger::GetAllSequencePoints (iter);
1280+
else
1281+
return (Il2CppSequencePoint*)il2cpp::utils::Debugger::GetSequencePoints((const MethodInfo*)method, iter);
12911282
#else
12921283
return NULL;
12931284
#endif
@@ -1477,10 +1468,10 @@ MonoClass* il2cpp_mono_get_string_class (void)
14771468
return (MonoClass*)il2cpp_defaults.string_class;
14781469
}
14791470

1480-
Il2CppSequencePoint* il2cpp_get_sequence_point(int id)
1471+
Il2CppSequencePoint* il2cpp_get_sequence_point(MonoImage* image, int id)
14811472
{
14821473
#if IL2CPP_MONO_DEBUGGER
1483-
return il2cpp::utils::Debugger::GetSequencePoint(id);
1474+
return il2cpp::utils::Debugger::GetSequencePoint(image, id);
14841475
#else
14851476
return NULL;
14861477
#endif
@@ -1565,5 +1556,20 @@ MonoType* il2cpp_mono_class_get_byref_type (MonoClass *klass)
15651556
return (MonoType*)il2cpp::vm::Class::GetByrefType((Il2CppClass*)klass);
15661557
}
15671558

1559+
Il2CppSequencePointSourceFile* il2cpp_debug_get_source_file(MonoImage* image, int index)
1560+
{
1561+
return ((Il2CppImage*)image)->codeGenModule->debuggerMetadata->sequencePointSourceFiles + index;
1562+
}
1563+
1564+
const char* il2cpp_debug_get_local_name(MonoImage* image, int index)
1565+
{
1566+
return ((Il2CppImage*)image)->codeGenModule->debuggerMetadata->methodExecutionContextInfoStrings[index];
1567+
}
1568+
1569+
Il2CppMethodScope* il2cpp_debug_get_local_scope(MonoImage* image, int index)
1570+
{
1571+
return ((Il2CppImage*)image)->codeGenModule->debuggerMetadata->methodScopes + index;
1572+
}
1573+
15681574
}
15691575
#endif // RUNTIME_IL2CPP

0 commit comments

Comments
 (0)