Skip to content

Commit 4a859c4

Browse files
authored
Merge pull request #1009 from Unity-Technologies/unity-master-il2cpp-debugger-sync
Apply debugger changes from il2cpp 0c52b0b5b2babc2cbec886b8ef8015f682…
2 parents f7192b6 + b6076e2 commit 4a859c4

File tree

3 files changed

+55
-114
lines changed

3 files changed

+55
-114
lines changed

mono/mini/debugger-agent.c

Lines changed: 39 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ typedef struct
163163
MonoContext ctx;
164164
#ifndef RUNTIME_IL2CPP
165165
MonoDebugMethodJitInfo *jit;
166+
#else
167+
Il2CppSequencePointExecutionContext* frame_context;
166168
#endif
167169
MonoJitInfo *ji;
168170
MonoInterpFrameHandle interp_frame;
@@ -3431,7 +3433,8 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls)
34313433
StackFrame* frame = g_new0(StackFrame, 1);
34323434
MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point);
34333435
frame->method = sp_method;
3434-
frame->actual_method = sp_method;
3436+
frame->actual_method = tls->il2cpp_context.executionContexts[frame_index]->method;
3437+
frame->frame_context = tls->il2cpp_context.executionContexts[frame_index];
34353438
frame->api_method = sp_method;
34363439
frame->il_offset = seq_point->ilOffset;
34373440
frame->native_offset = 0;
@@ -4802,7 +4805,7 @@ set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, MonoError
48024805
Il2CppSequencePoint *seqPoint;
48034806
while(seqPoint = il2cpp_get_method_sequence_points(method, &seqPointIter))
48044807
{
4805-
if (bp_matches_method(bp, il2cpp_get_seq_point_method(seqPoint)) && seqPoint->ilOffset == bp->il_offset)
4808+
if (seqPoint->ilOffset == bp->il_offset)
48064809
{
48074810
if (req->event_kind == EVENT_KIND_BREAKPOINT && seqPoint->kind == kSequencePointKind_StepOut)
48084811
continue;
@@ -10253,34 +10256,6 @@ static void GetSequencePointsAndSourceFilesUniqueSequencePoints(MonoMethod* meth
1025310256
}
1025410257
}
1025510258

10256-
static void GetExecutionContextAndHeaderInfo(MonoMethod* method, uint32_t* executionContextInfoCount, const Il2CppMethodExecutionContextInfo **executionContextInfo, const Il2CppMethodHeaderInfo **headerInfo, const Il2CppMethodScope **scopes)
10257-
{
10258-
void *seqPointIter = NULL;
10259-
Il2CppSequencePoint *seqPoint;
10260-
while (seqPoint = il2cpp_get_method_sequence_points(method, &seqPointIter))
10261-
{
10262-
if (il2cpp_mono_methods_match(il2cpp_get_seq_point_method(seqPoint), method))
10263-
{
10264-
Il2CppMethodExecutionContextInfoIndex *index = &g_il2cpp_metadata->methodExecutionContextInfoIndexes[seqPoint->methodIndex];
10265-
if (index->count != -1)
10266-
{
10267-
*executionContextInfoCount = index->count;
10268-
*executionContextInfo = &g_il2cpp_metadata->methodExecutionContextInfos[index->tableIndex][index->startIndex];
10269-
}
10270-
else
10271-
{
10272-
*executionContextInfoCount = 0;
10273-
*executionContextInfo = NULL;
10274-
}
10275-
*headerInfo = &g_il2cpp_metadata->methodHeaderInfos[seqPoint->methodIndex];
10276-
*scopes = &g_il2cpp_metadata->methodScopes[(*headerInfo)->startScope];
10277-
return;
10278-
}
10279-
}
10280-
10281-
g_assert(FALSE); // shouldn't be ever reached
10282-
}
10283-
1028410259
#endif // RUNTIME_IL2CPP
1028510260

1028610261
static ErrorCode
@@ -10535,12 +10510,12 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
1053510510
mono_debug_free_locals (locals);
1053610511
g_free (locals_map);
1053710512
#else
10538-
uint32_t executionInfoCount, localVariableCount = 0, i;
10513+
uint32_t executionInfoCount, i;
1053910514
const Il2CppMethodExecutionContextInfo* executionContextInfo = NULL;
1054010515
const Il2CppMethodHeaderInfo* headerInfo;
10541-
const Il2CppMethodScope* scopes;
10516+
const Il2CppMethodScope* scopes;
1054210517

10543-
GetExecutionContextAndHeaderInfo(method, &executionInfoCount, &executionContextInfo, &headerInfo, &scopes);
10518+
il2cpp_debugger_get_method_execution_context_and_header_Info (method, &executionInfoCount, &executionContextInfo, &headerInfo, &scopes);
1054410519

1054510520
if (CHECK_PROTOCOL_VERSION(2, 43)) {
1054610521
if (headerInfo)
@@ -10558,32 +10533,18 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
1055810533
}
1055910534
}
1056010535

10561-
for (i = 0; i < executionInfoCount; i++)
10562-
{
10563-
if (executionContextInfo[i].variableKind == kMethodVariableKind_LocalVariable)
10564-
localVariableCount++;
10565-
}
10566-
10567-
buffer_add_int(buf, localVariableCount);
10536+
buffer_add_int(buf, executionInfoCount);
1056810537

1056910538
for (i = 0; i < executionInfoCount; i++)
10570-
{
10571-
if (executionContextInfo[i].variableKind == kMethodVariableKind_LocalVariable)
10572-
buffer_add_typeid(buf, domain, mono_class_from_mono_type(il2cpp_get_type_from_index(executionContextInfo[i].typeIndex)));
10573-
}
10539+
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))));
1057410540

1057510541
for (i = 0; i < executionInfoCount; i++)
10576-
{
10577-
if (executionContextInfo[i].variableKind == kMethodVariableKind_LocalVariable)
10578-
buffer_add_string(buf, g_il2cpp_metadata->methodExecutionContextInfoStrings[executionContextInfo[i].nameIndex]);
10579-
}
10542+
buffer_add_string(buf, g_il2cpp_metadata->methodExecutionContextInfoStrings[executionContextInfo[i].nameIndex]);
1058010543

1058110544
for (i = 0; i < executionInfoCount; i++)
1058210545
{
10583-
if (executionContextInfo[i].variableKind == kMethodVariableKind_LocalVariable) {
10584-
buffer_add_int(buf, executionContextInfo[i].startOffset);
10585-
buffer_add_int(buf, executionContextInfo[i].endOffset);
10586-
}
10546+
buffer_add_int(buf, g_il2cpp_metadata->methodScopes[executionContextInfo[i].scopeIndex].startOffset);
10547+
buffer_add_int(buf, g_il2cpp_metadata->methodScopes[executionContextInfo[i].scopeIndex].endOffset);
1058710548
}
1058810549
#endif // !RUNTIME_IL2CPP
1058910550
break;
@@ -11016,42 +10977,31 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1101610977

1101710978
#ifdef RUNTIME_IL2CPP
1101810979

11019-
static uint32_t GetExecutionContextIndexAndType(const Il2CppSequencePoint* sequencePoint, MethodVariableKind variableKind, uint32_t variablePosition, MonoType **type)
10980+
static void GetVariable(DebuggerTlsData* tls, StackFrame* frame, MethodVariableKind variableKind, uint32_t variablePosition, MonoType** type, void** var)
1102010981
{
11021-
uint32_t executionContextPosition, variablesIterated = 0;
11022-
11023-
Il2CppMethodExecutionContextInfoIndex *index = &g_il2cpp_metadata->methodExecutionContextInfoIndexes[sequencePoint->methodIndex];
11024-
Il2CppMethodExecutionContextInfo *executionContextInfos = &g_il2cpp_metadata->methodExecutionContextInfos[index->tableIndex][index->startIndex];
11025-
11026-
for (executionContextPosition = 0;; executionContextPosition++)
11027-
{
11028-
g_assert(executionContextPosition < index->count);
11029-
11030-
if (executionContextInfos[executionContextPosition].variableKind == variableKind)
11031-
{
11032-
if (variablesIterated == variablePosition)
11033-
{
11034-
*type = il2cpp_get_type_from_index(executionContextInfos[executionContextPosition].typeIndex);
11035-
return executionContextPosition;
11036-
}
10982+
switch (variableKind)
10983+
{
10984+
case kMethodVariableKind_Parameter: {
10985+
*var = frame->frame_context->params[variablePosition];
10986+
*type = il2cpp_method_get_param (frame->actual_method, variablePosition);
10987+
}
10988+
break;
10989+
case kMethodVariableKind_LocalVariable: {
10990+
uint32_t executionInfoCount, localVariableCount = 0, i;
10991+
const Il2CppMethodExecutionContextInfo* executionContextInfo = NULL;
10992+
const Il2CppMethodHeaderInfo* headerInfo;
10993+
const Il2CppMethodScope* scopes;
1103710994

11038-
variablesIterated++;
11039-
}
11040-
}
11041-
}
10995+
il2cpp_debugger_get_method_execution_context_and_header_Info (frame->actual_method, &executionInfoCount, &executionContextInfo, &headerInfo, &scopes);
1104210996

11043-
static void GetVariable(DebuggerTlsData* tls, StackFrame* frame, MethodVariableKind variableKind, uint32_t variablePosition, MonoType** type, void** var)
11044-
{
11045-
for (int frame_index = 0; frame_index < tls->il2cpp_context.frameCount; ++frame_index)
11046-
{
11047-
if (il2cpp_get_seq_point_method(tls->il2cpp_context.sequencePoints[frame_index]) == frame->actual_method)
11048-
{
11049-
Il2CppSequencePoint* sequencePoint = tls->il2cpp_context.sequencePoints[frame_index];
11050-
Il2CppSequencePointExecutionContext* executionContext = tls->il2cpp_context.executionContexts[frame_index];
11051-
uint32_t executionContextPosition = GetExecutionContextIndexAndType(sequencePoint, variableKind, variablePosition, type);
11052-
*var = executionContext->values[executionContextPosition];
11053-
}
11054-
}
10997+
*var = frame->frame_context->locals[variablePosition];
10998+
*type = il2cpp_type_inflate ( il2cpp_get_type_from_index (executionContextInfo[variablePosition].typeIndex), il2cpp_mono_method_get_context (frame->actual_method));
10999+
}
11000+
break;
11001+
case kMethodVariableKind_This:
11002+
default:
11003+
g_assert_not_reached ();
11004+
}
1105511005
}
1105611006

1105711007
static void SendVariableData(DebuggerTlsData* tls, StackFrame* frame, Buffer* buf, MethodVariableKind variableKind, uint32_t variablePosition)
@@ -11217,14 +11167,8 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1121711167
add_var (buf, jit, &frame->actual_method->klass->this_arg, jit->this_var, &frame->ctx, frame->domain, TRUE);
1121811168
}
1121911169
#else
11220-
for (int frame_index = 0; frame_index < tls->il2cpp_context.frameCount; ++frame_index)
11221-
{
11222-
if (il2cpp_get_seq_point_method(tls->il2cpp_context.sequencePoints[frame_index]) == frame->actual_method)
11223-
{
11224-
buffer_add_value_full (buf, &frame->actual_method->klass->this_arg, tls->il2cpp_context.executionContexts[frame_index]->values[0], frame->domain, TRUE, NULL);
11225-
break;
11226-
}
11227-
}
11170+
buffer_add_value_full (buf, &frame->actual_method->klass->this_arg, *frame->frame_context->thisArg, frame->domain, FALSE, NULL);
11171+
break;
1122811172
#endif
1122911173
}
1123011174
} else {
@@ -11243,7 +11187,7 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1124311187
add_var (buf, jit, &frame->api_method->klass->byval_arg, jit->this_var, &frame->ctx, frame->domain, TRUE);
1124411188
}
1124511189
#else
11246-
SendVariableData (tls, frame, buf, kMethodVariableKind_This, 0);
11190+
buffer_add_value_full (buf, &frame->actual_method->klass->byval_arg, *frame->frame_context->thisArg, frame->domain, FALSE, NULL);
1124711191
#endif
1124811192
}
1124911193
}
@@ -11365,8 +11309,7 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
1136511309
set_var (&frame->actual_method->klass->this_arg, var, &frame->ctx, frame->domain, val_buf, frame->reg_locations, &tls->restore_state.ctx);
1136611310
}
1136711311
#else
11368-
GetVariable (tls, frame, kMethodVariableKind_This, 0, &t, &var);
11369-
il2cpp_set_var(val_buf, var, &frame->actual_method->klass->this_arg);
11312+
il2cpp_set_var(val_buf, *frame->frame_context->thisArg, &frame->actual_method->klass->this_arg);
1137011313
#endif
1137111314
break;
1137211315
}

mono/mini/il2cpp-compat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,5 +459,8 @@ char* il2cpp_assembly_get_full_name(MonoAssembly *assembly);
459459
const MonoMethod* il2cpp_get_seq_point_method(Il2CppSequencePoint *seqPoint);
460460
const MonoClass* il2cpp_get_class_from_index(int index);
461461
const MonoType* il2cpp_get_type_from_index(int index);
462+
const MonoType* il2cpp_get_type_from_method_context(MonoType* type, const MonoMethod* method);
463+
const MonoType* il2cpp_type_inflate(MonoType* type, const MonoGenericContext* context);
464+
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);
462465

463466
#endif // RUNTIME_IL2CPP

mono/mini/il2cpp-stubs.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,25 +1300,8 @@ gboolean il2cpp_mono_methods_match(MonoMethod* left, MonoMethod* right)
13001300
return TRUE;
13011301
if (rightMethod == NULL || leftMethod == NULL)
13021302
return FALSE;
1303-
if (rightMethod->is_inflated && !rightMethod->is_generic && rightMethod->genericMethod->methodDefinition == leftMethod)
1303+
if (leftMethod->methodDefinition == rightMethod->methodDefinition)
13041304
return TRUE;
1305-
if (leftMethod->is_inflated && !leftMethod->is_generic && leftMethod->genericMethod->methodDefinition == rightMethod)
1306-
return TRUE;
1307-
if (leftMethod->is_generic && rightMethod->is_inflated && rightMethod->methodPointer &&
1308-
leftMethod->klass == rightMethod->klass &&
1309-
strcmp(leftMethod->name, rightMethod->name) == 0)
1310-
{
1311-
if (leftMethod->parameters_count != rightMethod->parameters_count)
1312-
return FALSE;
1313-
1314-
for(int i = 0;i < leftMethod->parameters_count;++i)
1315-
{
1316-
if ((leftMethod->parameters[i].parameter_type->type != IL2CPP_TYPE_MVAR) && (leftMethod->parameters[i].parameter_type->type != IL2CPP_TYPE_VAR) && (leftMethod->parameters[i].parameter_type != rightMethod->parameters[i].parameter_type))
1317-
return FALSE;
1318-
}
1319-
1320-
return TRUE;
1321-
}
13221305

13231306
return FALSE;
13241307
}
@@ -1529,5 +1512,17 @@ const MonoType* il2cpp_get_type_from_index(int index)
15291512
return il2cpp::vm::MetadataCache::GetIl2CppTypeFromIndex(index);
15301513
}
15311514

1515+
const MonoType* il2cpp_type_inflate(MonoType* type, const MonoGenericContext* context)
1516+
{
1517+
return il2cpp::metadata::GenericMetadata::InflateIfNeeded(type, context, true);
1518+
}
1519+
1520+
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)
1521+
{
1522+
#if IL2CPP_MONO_DEBUGGER
1523+
il2cpp::utils::Debugger::GetMethodExecutionContextInfo(method, executionContextInfoCount, executionContextInfo, headerInfo, scopes);
1524+
#endif
1525+
}
1526+
15321527
}
15331528
#endif // RUNTIME_IL2CPP

0 commit comments

Comments
 (0)