Skip to content

Commit 56ea90e

Browse files
committed
Initial work to allow debugger attaching without performance impact.
1 parent 2ff182b commit 56ea90e

File tree

3 files changed

+68
-20
lines changed

3 files changed

+68
-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: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,61 @@ 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 (const char *message)
1096+
{
1097+
stop_debugger_thread ();
1098+
}
1099+
1100+
typedef void (*MonoDebuggerAttachFunc)(gboolean attached);
1101+
static MonoDebuggerAttachFunc attach_func;
1102+
MONO_API void
1103+
mono_debugger_install_attach_detach_callback (MonoDebuggerAttachFunc func)
1104+
{
1105+
attach_func = func;
1106+
}
1107+
10531108
void
10541109
mono_debugger_agent_init (void)
10551110
{
@@ -1117,26 +1172,7 @@ mono_debugger_agent_init (void)
11171172
breakpoints_init ();
11181173
suspend_init ();
11191174

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
1175+
update_mdb_optimizations ();
11401176

11411177
#ifdef HAVE_SETPGID
11421178
if (agent_config.setpgid)
@@ -4659,6 +4695,8 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo
46594695
mini_get_interp_callbacks ()->set_breakpoint (ji, inst->ip);
46604696
} else {
46614697
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
4698+
if (ji->dbg_ignore)
4699+
return;
46624700
mono_arch_set_breakpoint (ji, inst->ip);
46634701
#else
46644702
NOT_IMPLEMENTED;
@@ -11992,6 +12030,8 @@ debugger_thread (void *arg)
1199212030
attach_failed = TRUE; // Don't abort process when we can't listen
1199312031
} else {
1199412032
mono_set_is_debugger_attached (TRUE);
12033+
if (attach_func)
12034+
attach_func (TRUE);
1199512035
/* Send start event to client */
1199612036
process_profiler_event (EVENT_KIND_VM_START, mono_thread_get_main ());
1199712037
#ifdef RUNTIME_IL2CPP
@@ -12008,6 +12048,8 @@ debugger_thread (void *arg)
1200812048
}
1200912049
} else {
1201012050
mono_set_is_debugger_attached (TRUE);
12051+
if (attach_func)
12052+
attach_func (TRUE);
1201112053
}
1201212054

1201312055
while (!attach_failed) {
@@ -12142,6 +12184,8 @@ debugger_thread (void *arg)
1214212184
}
1214312185

1214412186
mono_set_is_debugger_attached (FALSE);
12187+
if (attach_func)
12188+
attach_func (FALSE);
1214512189

1214612190
#ifdef RUNTIME_IL2CPP
1214712191
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)