Skip to content

Commit f93c597

Browse files
authored
Merge pull request #1158 from Unity-Technologies/unity-master-debugger-perf
Initial work to allow debugger attaching without performance impact.
2 parents f5bd600 + 243d0eb commit f93c597

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-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: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,63 @@ mono_debugger_agent_parse_options (char *options)
10501050
}
10511051
}
10521052

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

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

11411179
#ifdef HAVE_SETPGID
11421180
if (agent_config.setpgid)
@@ -4659,6 +4697,8 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo
46594697
mini_get_interp_callbacks ()->set_breakpoint (ji, inst->ip);
46604698
} else {
46614699
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
4700+
if (ji->dbg_ignore)
4701+
return;
46624702
mono_arch_set_breakpoint (ji, inst->ip);
46634703
#else
46644704
NOT_IMPLEMENTED;
@@ -12003,6 +12043,8 @@ debugger_thread (void *arg)
1200312043
attach_failed = TRUE; // Don't abort process when we can't listen
1200412044
} else {
1200512045
mono_set_is_debugger_attached (TRUE);
12046+
if (attach_func)
12047+
attach_func (TRUE);
1200612048
/* Send start event to client */
1200712049
process_profiler_event (EVENT_KIND_VM_START, mono_thread_get_main ());
1200812050
#ifdef RUNTIME_IL2CPP
@@ -12019,6 +12061,8 @@ debugger_thread (void *arg)
1201912061
}
1202012062
} else {
1202112063
mono_set_is_debugger_attached (TRUE);
12064+
if (attach_func)
12065+
attach_func (TRUE);
1202212066
}
1202312067

1202412068
while (!attach_failed) {
@@ -12153,6 +12197,8 @@ debugger_thread (void *arg)
1215312197
}
1215412198

1215512199
mono_set_is_debugger_attached (FALSE);
12200+
if (attach_func)
12201+
attach_func (FALSE);
1215612202

1215712203
#ifdef RUNTIME_IL2CPP
1215812204
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)