Skip to content

Commit 04ff174

Browse files
author
Joshua Peterson
authored
Merge pull request #1184 from Unity-Technologies/sync-debugger-from-il2cpp-2
Sync the debugger agent code from IL2CPP
2 parents 9f684e0 + 8d86df9 commit 04ff174

File tree

1 file changed

+81
-52
lines changed

1 file changed

+81
-52
lines changed

mono/mini/debugger-agent.c

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ typedef struct {
286286
typedef struct {
287287
const char *name;
288288
void (*connect) (const char *address);
289+
int (*wait_for_attach) (void);
289290
void (*close1) (void);
290291
void (*close2) (void);
291-
gboolean (*send) (void *buf, int len);
292+
int (*send) (void *buf, int len);
292293
int (*recv) (void *buf, int len);
293294
} DebuggerTransport;
294295

@@ -1330,6 +1331,26 @@ socket_transport_accept (int socket_fd)
13301331
return conn_fd;
13311332
}
13321333

1334+
static int
1335+
socket_transport_wait_for_attach(void)
1336+
{
1337+
if (listen_fd == -1) {
1338+
DEBUG_PRINTF(1, "[dbg] Invalid listening socket\n");
1339+
return 0;
1340+
}
1341+
1342+
/* Block and wait for client connection */
1343+
conn_fd = socket_transport_accept(listen_fd);
1344+
1345+
DEBUG_PRINTF(1, "Accepted connection on %d\n", conn_fd);
1346+
if (conn_fd == -1) {
1347+
DEBUG_PRINTF(1, "[dbg] Bad client connection\n");
1348+
return 0;
1349+
}
1350+
1351+
return 1;
1352+
}
1353+
13331354
static gboolean
13341355
socket_transport_send (void *data, int len)
13351356
{
@@ -1560,6 +1581,7 @@ register_socket_transport (void)
15601581

15611582
trans.name = "dt_socket";
15621583
trans.connect = socket_transport_connect;
1584+
trans.wait_for_attach = socket_transport_wait_for_attach;
15631585
trans.close1 = socket_transport_close1;
15641586
trans.close2 = socket_transport_close2;
15651587
trans.send = socket_transport_send;
@@ -1595,6 +1617,7 @@ register_socket_fd_transport (void)
15951617
/* This is the same as the 'dt_socket' transport, but receives an already connected socket fd */
15961618
trans.name = "socket-fd";
15971619
trans.connect = socket_fd_transport_connect;
1620+
trans.wait_for_attach = socket_transport_wait_for_attach;
15981621
trans.close1 = socket_transport_close1;
15991622
trans.close2 = socket_transport_close2;
16001623
trans.send = socket_transport_send;
@@ -1664,6 +1687,12 @@ transport_connect (const char *address)
16641687
transport->connect (address);
16651688
}
16661689

1690+
int
1691+
transport_wait_for_attach(void)
1692+
{
1693+
return transport->wait_for_attach ();
1694+
}
1695+
16671696
static void
16681697
transport_close1 (void)
16691698
{
@@ -3824,7 +3853,7 @@ create_event_list (EventKind event, GPtrArray *reqs, MonoJitInfo *ji, DebuggerEv
38243853
break;
38253854
}
38263855
#else
3827-
while (!found && (method = mono_class_get_methods (ei->klass, &iter))) {
3856+
while ((method = mono_class_get_methods (ei->klass, &iter))) {
38283857
MonoDebugMethodInfo *minfo = mono_debug_lookup_method (method);
38293858

38303859
if (minfo) {
@@ -5423,7 +5452,7 @@ static MonoMethod* notify_debugger_of_wait_completion_method_cache = NULL;
54235452
static MonoMethod*
54245453
get_notify_debugger_of_wait_completion_method (void)
54255454
{
5426-
#if IL2CPP_TINY
5455+
#if IL2CPP_DOTS
54275456
return NULL;
54285457
#else
54295458
if (notify_debugger_of_wait_completion_method_cache != NULL)
@@ -5436,7 +5465,7 @@ get_notify_debugger_of_wait_completion_method (void)
54365465
notify_debugger_of_wait_completion_method_cache = (MonoMethod *)g_ptr_array_index (array, 0);
54375466
g_ptr_array_free (array, TRUE);
54385467
return notify_debugger_of_wait_completion_method_cache;
5439-
#endif // IL2CPP_TINY
5468+
#endif // IL2CPP_DOTS
54405469
}
54415470

54425471
#ifndef RUNTIME_IL2CPP
@@ -6823,20 +6852,27 @@ mono_debugger_agent_unhandled_exception (MonoException *exc)
68236852
#endif
68246853

68256854
#ifdef RUNTIME_IL2CPP
6826-
static Il2CppSequencePoint* il2cpp_find_catch_sequence_point_in_method(Il2CppSequencePoint* callSp, MonoException *exc)
6855+
static Il2CppCatchPoint* il2cpp_find_catch_point_in_method(const MonoMethod *method, int8_t tryId, MonoException *exc)
68276856
{
6828-
uint8_t tryDepth = callSp->tryDepth;
6829-
MonoMethod *method = il2cpp_get_seq_point_method(callSp);
6830-
int32_t ilOffset = callSp->ilOffset;
6831-
Il2CppSequencePoint *sp;
6857+
Il2CppCatchPoint *cp;
6858+
int8_t nextId = tryId, id;
68326859

6833-
void *seqPointIter = NULL;
6834-
while (sp = il2cpp_get_method_sequence_points(method, &seqPointIter))
6860+
while(nextId >= 0)
68356861
{
6836-
MonoClass *catchType = il2cpp_get_class_from_index(sp->catchTypeIndex);
6837-
if (sp->tryDepth == tryDepth && sp->ilOffset > ilOffset && catchType != NULL && mono_class_is_assignable_from (catchType, mono_object_get_class (&exc->object)))
6838-
return sp;
6839-
}
6862+
id = nextId;
6863+
nextId = -1;
6864+
void *catchPointIter = NULL;
6865+
while (cp = il2cpp_get_method_catch_points(method, &catchPointIter))
6866+
{
6867+
if (cp->tryId == id)
6868+
{
6869+
MonoClass *catchType = il2cpp_get_class_from_index(cp->catchTypeIndex);
6870+
nextId = cp->parentTryId;
6871+
if (catchType != NULL && mono_class_is_assignable_from (catchType, mono_object_get_class (&exc->object)))
6872+
return cp;
6873+
}
6874+
}
6875+
}
68406876

68416877
return NULL;
68426878
}
@@ -6846,42 +6882,45 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point(DebuggerTlsData *tl
68466882
int frameIndex = tls->il2cpp_context->frameCount - 1;
68476883
while (frameIndex >= 0)
68486884
{
6849-
Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, tls->exception);
6850-
if (sp)
6851-
return sp;
6885+
Il2CppCatchPoint* cp = il2cpp_find_catch_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->method, tls->il2cpp_context->executionContexts[frameIndex]->tryId, tls->exception);
6886+
if (cp)
6887+
{
6888+
Il2CppSequencePoint* sp = il2cpp_get_seq_point_from_catch_point(cp);
6889+
if (sp)
6890+
return sp;
6891+
else
6892+
return NULL;
6893+
}
68526894

68536895
--frameIndex;
68546896
}
68556897

68566898
return NULL;
68576899
}
68586900

6859-
static Il2CppSequencePoint* il2cpp_find_catch_sequence_point_from_exeption(DebuggerTlsData *tls, MonoException *exc, Il2CppSequencePoint *firstSp)
6901+
static void il2cpp_find_catch_sequence_point_from_exeption(DebuggerTlsData *tls, MonoException *exc, Il2CppCatchPoint **catchPt, Il2CppSequencePoint **seqPt)
68606902
{
6861-
Il2CppSequencePoint* sp;
6862-
6863-
if (firstSp)
6864-
{
6865-
sp = il2cpp_find_catch_sequence_point_in_method(firstSp, exc);
6866-
if (sp)
6867-
return sp;
6868-
}
6903+
*catchPt = NULL;
6904+
*seqPt = NULL;
68696905

68706906
int frameIndex = tls->il2cpp_context->frameCount - 1;
68716907
while (frameIndex >= 0)
68726908
{
6873-
sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, exc);
6874-
if (sp)
6875-
return sp;
6909+
*catchPt = il2cpp_find_catch_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->method, tls->il2cpp_context->executionContexts[frameIndex]->tryId, exc);
6910+
if (*catchPt)
6911+
{
6912+
*seqPt = il2cpp_get_seq_point_from_catch_point(*catchPt);
6913+
return;
6914+
}
68766915

68776916
--frameIndex;
68786917
}
68796918

6880-
return NULL;
6919+
return;
68816920
}
68826921

68836922
void
6884-
unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *sequencePoint)
6923+
unity_debugger_agent_handle_exception(MonoException *exc)
68856924
{
68866925
int i, j, suspend_policy;
68876926
GSList *events;
@@ -6906,18 +6945,19 @@ unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *s
69066945

69076946
ei.exc = (MonoObject*)exc;
69086947
ei.caught = FALSE;
6909-
Il2CppSequencePoint *catchSp = NULL;
6948+
Il2CppCatchPoint *catchPt;
6949+
Il2CppSequencePoint *seqPt;
69106950

69116951
if (tls)
69126952
{
6913-
catchSp = il2cpp_find_catch_sequence_point_from_exeption(tls, exc, sequencePoint);
6914-
if (catchSp)
6953+
il2cpp_find_catch_sequence_point_from_exeption(tls, exc, &catchPt, &seqPt);
6954+
if (catchPt)
69156955
ei.caught = TRUE;
69166956
}
69176957

69186958
mono_loader_lock();
69196959

6920-
MonoMethod *sp_method = il2cpp_get_seq_point_method(sequencePoint);
6960+
MonoMethod *method = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->method;
69216961

69226962
/* Treat exceptions which are caught in non-user code as unhandled */
69236963
for (i = 0; i < event_requests->len; ++i)
@@ -6930,7 +6970,7 @@ unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *s
69306970
{
69316971
Modifier *mod = &req->modifiers[j];
69326972

6933-
if (mod->kind == MOD_KIND_ASSEMBLY_ONLY && sequencePoint)
6973+
if (mod->kind == MOD_KIND_ASSEMBLY_ONLY && method)
69346974
{
69356975
int k;
69366976
gboolean found = FALSE;
@@ -6939,7 +6979,7 @@ unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *s
69396979
if (assemblies)
69406980
{
69416981
for (k = 0; assemblies[k]; ++k)
6942-
if (assemblies[k] == mono_image_get_assembly (mono_class_get_image (mono_method_get_class (sp_method))))
6982+
if (assemblies[k] == mono_image_get_assembly (mono_class_get_image (mono_method_get_class (method))))
69436983
found = TRUE;
69446984
}
69456985
if (!found)
@@ -6955,11 +6995,11 @@ unity_debugger_agent_handle_exception(MonoException *exc, Il2CppSequencePoint *s
69556995
{
69566996
if (!ss_req || !ss_req->bps) {
69576997
tls->exception = exc;
6958-
} else if (ss_req->bps && catchSp) {
6998+
} else if (ss_req->bps && seqPt) {
69596999
int ss_req_bp_count = g_slist_length(ss_req->bps);
69607000
GHashTable *ss_req_bp_cache = NULL;
69617001

6962-
ss_bp_add_one_il2cpp(ss_req, &ss_req_bp_count, &ss_req_bp_cache, catchSp);
7002+
ss_bp_add_one_il2cpp(ss_req, &ss_req_bp_count, &ss_req_bp_cache, seqPt);
69637003

69647004
if (ss_req_bp_cache)
69657005
g_hash_table_destroy(ss_req_bp_cache);
@@ -11892,19 +11932,8 @@ static gboolean
1189211932
wait_for_attach (void)
1189311933
{
1189411934
#ifndef DISABLE_SOCKET_TRANSPORT
11895-
if (listen_fd == -1) {
11896-
DEBUG_PRINTF (1, "[dbg] Invalid listening socket\n");
11897-
return FALSE;
11898-
}
11899-
11900-
/* Block and wait for client connection */
11901-
conn_fd = socket_transport_accept (listen_fd);
11902-
11903-
DEBUG_PRINTF (1, "Accepted connection on %d\n", conn_fd);
11904-
if (conn_fd == -1) {
11905-
DEBUG_PRINTF (1, "[dbg] Bad client connection\n");
11935+
if (!transport_wait_for_attach())
1190611936
return FALSE;
11907-
}
1190811937
#else
1190911938
g_assert_not_reached ();
1191011939
#endif

0 commit comments

Comments
 (0)