Skip to content

Commit 9bb3915

Browse files
committed
Initial work to allow debugger attaching without performance impact.
1 parent acf432a commit 9bb3915

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

mono/metadata/domain-internals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ struct _MonoJitInfo {
246246
/* Whenever this jit info refers to an interpreter method */
247247
gboolean is_interp:1;
248248

249+
gboolean dbg_ignore : 1;
250+
249251
/* FIXME: Embed this after the structure later*/
250252
gpointer gc_info; /* Currently only used by SGen */
251253

mono/mini/debugger-agent.c

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,55 @@ mono_debugger_agent_parse_options (char *options)
10491049
}
10501050
}
10511051

1052+
static gboolean disable_optimizations = TRUE;
1053+
1054+
static void
1055+
update_mdb_optimizations ()
1056+
{
1057+
gboolean enable = disable_optimizations;
1058+
#ifndef RUNTIME_IL2CPP
1059+
mini_get_debug_options ()->gen_sdb_seq_points = enable;
1060+
/*
1061+
* This is needed because currently we don't handle liveness info.
1062+
*/
1063+
mini_get_debug_options ()->mdb_optimizations = enable;
1064+
1065+
#ifndef MONO_ARCH_HAVE_CONTEXT_SET_INT_REG
1066+
/* This is needed because we can't set local variables in registers yet */
1067+
mono_disable_optimizations (MONO_OPT_LINEARS);
1068+
#endif
1069+
1070+
/*
1071+
* The stack walk done from thread_interrupt () needs to be signal safe, but it
1072+
* isn't, since it can call into mono_aot_find_jit_info () which is not signal
1073+
* safe (#3411). So load AOT info eagerly when the debugger is running as a
1074+
* workaround.
1075+
*/
1076+
mini_get_debug_options ()->load_aot_jit_info_eagerly = enable;
1077+
#endif // !RUNTIME_IL2CPP
1078+
}
1079+
1080+
MONO_API void
1081+
mono_debugger_set_disable_optimizations (gboolean enable)
1082+
{
1083+
disable_optimizations = enable;
1084+
update_mdb_optimizations ();
1085+
}
1086+
1087+
MONO_API gboolean
1088+
mono_debugger_get_disable_optimizations ()
1089+
{
1090+
return disable_optimizations;
1091+
}
1092+
1093+
typedef void (*MonoDebuggerAttachFunc)(gboolean attached);
1094+
static MonoDebuggerAttachFunc attach_func;
1095+
MONO_API void
1096+
mono_debugger_install_attach_detach_callback (MonoDebuggerAttachFunc func)
1097+
{
1098+
attach_func = func;
1099+
}
1100+
10521101
void
10531102
mono_debugger_agent_init (void)
10541103
{
@@ -1116,26 +1165,7 @@ mono_debugger_agent_init (void)
11161165
breakpoints_init ();
11171166
suspend_init ();
11181167

1119-
#ifndef RUNTIME_IL2CPP
1120-
mini_get_debug_options ()->gen_sdb_seq_points = TRUE;
1121-
/*
1122-
* This is needed because currently we don't handle liveness info.
1123-
*/
1124-
mini_get_debug_options ()->mdb_optimizations = TRUE;
1125-
1126-
#ifndef MONO_ARCH_HAVE_CONTEXT_SET_INT_REG
1127-
/* This is needed because we can't set local variables in registers yet */
1128-
mono_disable_optimizations (MONO_OPT_LINEARS);
1129-
#endif
1130-
1131-
/*
1132-
* The stack walk done from thread_interrupt () needs to be signal safe, but it
1133-
* isn't, since it can call into mono_aot_find_jit_info () which is not signal
1134-
* safe (#3411). So load AOT info eagerly when the debugger is running as a
1135-
* workaround.
1136-
*/
1137-
mini_get_debug_options ()->load_aot_jit_info_eagerly = TRUE;
1138-
#endif // !RUNTIME_IL2CPP
1168+
update_mdb_optimizations ();
11391169

11401170
#ifdef HAVE_SETPGID
11411171
if (agent_config.setpgid)
@@ -4630,6 +4660,8 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo
46304660
mini_get_interp_callbacks ()->set_breakpoint (ji, inst->ip);
46314661
} else {
46324662
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
4663+
if (ji->dbg_ignore)
4664+
return;
46334665
mono_arch_set_breakpoint (ji, inst->ip);
46344666
#else
46354667
NOT_IMPLEMENTED;
@@ -11963,6 +11995,8 @@ debugger_thread (void *arg)
1196311995
attach_failed = TRUE; // Don't abort process when we can't listen
1196411996
} else {
1196511997
mono_set_is_debugger_attached (TRUE);
11998+
if (attach_func)
11999+
attach_func (TRUE);
1196612000
/* Send start event to client */
1196712001
process_profiler_event (EVENT_KIND_VM_START, mono_thread_get_main ());
1196812002
#ifdef RUNTIME_IL2CPP
@@ -11979,6 +12013,8 @@ debugger_thread (void *arg)
1197912013
}
1198012014
} else {
1198112015
mono_set_is_debugger_attached (TRUE);
12016+
if (attach_func)
12017+
attach_func (TRUE);
1198212018
}
1198312019

1198412020
while (!attach_failed) {
@@ -12113,6 +12149,8 @@ debugger_thread (void *arg)
1211312149
}
1211412150

1211512151
mono_set_is_debugger_attached (FALSE);
12152+
if (attach_func)
12153+
attach_func (FALSE);
1211612154

1211712155
#ifdef RUNTIME_IL2CPP
1211812156
il2cpp_mono_free_method_signatures();

mono/mini/mini.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,6 +2809,8 @@ create_jit_info (MonoCompile *cfg, MonoMethod *method_to_compile)
28092809
jinfo->unwind_info = cfg->used_int_regs;
28102810
}
28112811

2812+
jinfo->dbg_ignore = !cfg->gen_sdb_seq_points;
2813+
28122814
return jinfo;
28132815
}
28142816

0 commit comments

Comments
 (0)