#include <mono/metadata/mono-debug-debugger.h>
#include <mono/metadata/debug-mono-symfile.h>
#include <mono/metadata/gc-internal.h>
+#include <mono/metadata/environment.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/socket-io.h>
#include <mono/metadata/assembly.h>
gboolean embedding;
gboolean defer;
int keepalive;
+ gboolean setpgid;
} AgentConfig;
typedef struct
#define HEADER_LENGTH 11
#define MAJOR_VERSION 2
-#define MINOR_VERSION 24
+#define MINOR_VERSION 27
typedef enum {
CMD_SET_VM = 1,
typedef enum {
STEP_FILTER_NONE = 0,
STEP_FILTER_STATIC_CTOR = 1,
- STEP_FILTER_DEBUGGER_HIDDEN = 2
+ STEP_FILTER_DEBUGGER_HIDDEN = 2,
+ STEP_FILTER_DEBUGGER_STEP_THROUGH = 4
} StepFilter;
typedef enum {
GHashTable *type_names; /* For kind == MONO_KIND_TYPE_NAME_ONLY */
StepFilter filter; /* For kind == MOD_KIND_STEP */
} data;
- gboolean caught, uncaught; /* For kind == MOD_KIND_EXCEPTION_ONLY */
+ gboolean caught, uncaught, subclasses; /* For kind == MOD_KIND_EXCEPTION_ONLY */
} Modifier;
typedef struct{
gboolean global;
/* The list of breakpoints used to implement step-over */
GSList *bps;
+ /* The number of frames at the start of a step-over */
+ int nframes;
} SingleStepReq;
/*
fprintf (stderr, " timeout=<n>\t\t\tTimeout for connecting in milliseconds.\n");
fprintf (stderr, " server=y/n\t\t\tWhether to listen for a client connection.\n");
fprintf (stderr, " keepalive=<n>\t\t\tSend keepalive events every n milliseconds.\n");
+ fprintf (stderr, " setpgid=y/n\t\t\tWhether to call setpid(0, 0) after startup.\n");
fprintf (stderr, " help\t\t\t\tPrint this help.\n");
}
agent_config.embedding = atoi (arg + 10) == 1;
} else if (strncmp (arg, "keepalive=", 10) == 0) {
agent_config.keepalive = atoi (arg + 10);
+ } else if (strncmp (arg, "setpgid=", 8) == 0) {
+ agent_config.setpgid = parse_flag ("setpgid", arg + 8);
} else {
print_usage ();
exit (1);
*/
mini_get_debug_options ()->load_aot_jit_info_eagerly = TRUE;
+#ifdef HAVE_SETPGID
+ if (agent_config.setpgid)
+ setpgid (0, 0);
+#endif
+
if (!agent_config.onuncaught && !agent_config.onthrow)
finish_agent_init (TRUE);
}
static void
start_debugger_thread (void)
{
- gsize tid;
-
- debugger_thread_handle = mono_create_thread (NULL, 0, debugger_thread, NULL, 0, &tid);
+ debugger_thread_handle = mono_threads_create_thread (debugger_thread, NULL, 0, 0, NULL);
g_assert (debugger_thread_handle);
}
if (mod->data.thread != mono_thread_internal_current ())
filtered = TRUE;
} else if (mod->kind == MOD_KIND_EXCEPTION_ONLY && ei) {
- if (mod->data.exc_class && !mono_class_is_assignable_from (mod->data.exc_class, ei->exc->vtable->klass))
+ if (mod->data.exc_class && mod->subclasses && !mono_class_is_assignable_from (mod->data.exc_class, ei->exc->vtable->klass))
+ filtered = TRUE;
+ if (mod->data.exc_class && !mod->subclasses && mod->data.exc_class != ei->exc->vtable->klass)
filtered = TRUE;
if (ei->caught && !mod->caught)
filtered = TRUE;
if (ji->dbg_hidden)
filtered = TRUE;
}
+ if ((mod->data.filter & STEP_FILTER_DEBUGGER_STEP_THROUGH) && ji) {
+ MonoCustomAttrInfo *ainfo;
+ static MonoClass *klass;
+
+ if (!klass) {
+ klass = mono_class_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerStepThroughAttribute");
+ g_assert (klass);
+ }
+ if (!ji->dbg_step_through_inited) {
+ ainfo = mono_custom_attrs_from_method (jinfo_get_method (ji));
+ if (ainfo) {
+ if (mono_custom_attrs_has_attr (ainfo, klass))
+ ji->dbg_step_through = TRUE;
+ mono_custom_attrs_free (ainfo);
+ }
+ ainfo = mono_custom_attrs_from_class (jinfo_get_method (ji)->klass);
+ if (ainfo) {
+ if (mono_custom_attrs_has_attr (ainfo, klass))
+ ji->dbg_step_through = TRUE;
+ mono_custom_attrs_free (ainfo);
+ }
+ ji->dbg_step_through_inited = TRUE;
+ }
+ if (ji->dbg_step_through)
+ filtered = TRUE;
+ }
}
}
buffer_add_domainid (&buf, mono_get_root_domain ());
break;
case EVENT_KIND_VM_DEATH:
+ if (CHECK_PROTOCOL_VERSION (2, 27))
+ buffer_add_int (&buf, mono_environment_exitcode_get ());
break;
case EVENT_KIND_EXCEPTION: {
EventInfo *ei = arg;
* Return FALSE if single stepping needs to continue.
*/
static gboolean
-ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp)
+ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *tls, MonoContext *ctx)
{
MonoDebugMethodInfo *minfo;
MonoDebugSourceLocation *loc = NULL;
return FALSE;
}
+ if (req->depth == STEP_DEPTH_OVER && hit) {
+ if (!tls->context.valid)
+ mono_thread_state_init_from_monoctx (&tls->context, ctx);
+ compute_frame_info (tls->thread, tls);
+ if (req->nframes && tls->frame_count && tls->frame_count > req->nframes) {
+ /* Hit the breakpoint in a recursive call */
+ DEBUG (1, fprintf (log_file, "[%p] Breakpoint at lower frame while stepping over, continuing single stepping.\n", (gpointer)GetCurrentThreadId ()));
+ return FALSE;
+ }
+ }
+
if (req->size != STEP_SIZE_LINE)
return TRUE;
SingleStepReq *ss_req = req->info;
gboolean hit;
- hit = ss_update (ss_req, ji, sp);
+ if (mono_thread_internal_current () != ss_req->thread)
+ continue;
+
+ hit = ss_update (ss_req, ji, sp, tls, ctx);
if (hit)
g_ptr_array_add (ss_reqs, req);
{
DebuggerTlsData *tls;
MonoContext orig_restore_ctx, ctx;
- static void (*restore_context) (void *);
-
- if (!restore_context)
- restore_context = mono_get_restore_context ();
tls = mono_native_tls_get_value (debugger_tls_id);
/* Have to save/restore the restore_ctx as we can be called recursively during invokes etc. */
/* This is called when resuming from a signal handler, so it shouldn't return */
memcpy (&ctx, &tls->restore_ctx, sizeof (MonoContext));
memcpy (&tls->restore_ctx, &orig_restore_ctx, sizeof (MonoContext));
- restore_context (&ctx);
+ mono_restore_context (&ctx);
g_assert_not_reached ();
}
return;
il_offset = sp->il_offset;
- if (!ss_update (ss_req, ji, sp))
+ if (!ss_update (ss_req, ji, sp, tls, ctx))
return;
/* Start single stepping again from the current sequence point */
}
if (ss_req->depth == STEP_DEPTH_OVER) {
+ if (ss_req->nframes == 0)
+ ss_req->nframes = tls->frame_count;
/* Need to stop in catch clauses as well */
for (i = 0; i < tls->frame_count; ++i) {
StackFrame *frame = tls->frames [i];
NOT_IMPLEMENTED;
break;
case MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET_INDIR:
+ case MONO_DEBUG_VAR_ADDRESS_MODE_VTADDR:
/* Same as regoffset, but with an indirection */
addr = (gpointer)mono_arch_context_get_int_reg (ctx, reg);
addr += (gint32)var->offset;
mgreg_t v;
gboolean is_signed = FALSE;
+ if (t->byref) {
+ addr = (gpointer)mono_arch_context_get_int_reg (ctx, reg);
+
+ if (addr) {
+ // FIXME: Write barriers
+ mono_gc_memmove (addr, val, size);
+ }
+ break;
+ }
+
if (!t->byref && (t->type == MONO_TYPE_I1 || t->type == MONO_TYPE_I2 || t->type == MONO_TYPE_I4 || t->type == MONO_TYPE_I8))
is_signed = TRUE;
g_assert_not_reached ();
}
- if (t->byref)
- NOT_IMPLEMENTED;
-
/* Set value on the stack or in the return ctx */
if (reg_locations [reg]) {
/* Saved on the stack */
/* Setup our lmf */
memset (&ext, 0, sizeof (ext));
-#ifdef TARGET_AMD64
- ext.lmf.previous_lmf = *(lmf_addr);
- /* Mark that this is a MonoLMFExt */
- ext.lmf.previous_lmf = (gpointer)(((gssize)ext.lmf.previous_lmf) | 2);
- ext.lmf.rsp = (gssize)&ext;
-#elif defined(TARGET_X86)
- ext.lmf.previous_lmf = (gsize)*(lmf_addr);
- /* Mark that this is a MonoLMFExt */
- ext.lmf.previous_lmf = (gsize)(gpointer)(((gssize)ext.lmf.previous_lmf) | 2);
- ext.lmf.ebp = (gssize)&ext;
-#elif defined(TARGET_ARM)
- ext.lmf.previous_lmf = *(lmf_addr);
- /* Mark that this is a MonoLMFExt */
- ext.lmf.previous_lmf = (gpointer)(((gssize)ext.lmf.previous_lmf) | 2);
- ext.lmf.sp = (gssize)&ext;
-#elif defined(TARGET_POWERPC)
- ext.lmf.previous_lmf = *(lmf_addr);
- /* Mark that this is a MonoLMFExt */
- ext.lmf.previous_lmf = (gpointer)(((gssize)ext.lmf.previous_lmf) | 2);
- ext.lmf.ebp = (gssize)&ext;
-#elif defined(TARGET_S390X)
- ext.lmf.previous_lmf = *(lmf_addr);
- /* Mark that this is a MonoLMFExt */
- ext.lmf.previous_lmf = (gpointer)(((gssize)ext.lmf.previous_lmf) | 2);
- ext.lmf.ebp = (gssize)&ext;
-#elif defined(TARGET_MIPS)
- ext.lmf.previous_lmf = *(lmf_addr);
- /* Mark that this is a MonoLMFExt */
- ext.lmf.previous_lmf = (gpointer)(((gssize)ext.lmf.previous_lmf) | 2);
- ext.lmf.iregs [mips_sp] = (gssize)&ext;
-#else
- g_assert_not_reached ();
-#endif
+ mono_arch_init_lmf_ext (&ext, *lmf_addr);
ext.debugger_invoke = TRUE;
memcpy (&ext.ctx, &invoke->ctx, sizeof (MonoContext));
int id;
int i, err, mindex;
Buffer buf;
- static void (*restore_context) (void *);
MonoContext restore_ctx;
guint8 *p;
- if (!restore_context)
- restore_context = mono_get_restore_context ();
-
tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
if (!mono_runtime_try_shutdown ())
break;
+ mono_environment_exitcode_set (exit_code);
+
/* Suspend all managed threads since the runtime is going away */
DEBUG(1, fprintf (log_file, "Suspending all threads...\n"));
mono_thread_suspend_all_other_threads ();
if (CHECK_PROTOCOL_VERSION (2, 16))
filter = decode_int (p, &p, end);
req->modifiers [i].data.filter = filter;
+ if (!CHECK_PROTOCOL_VERSION (2, 26) && (req->modifiers [i].data.filter & STEP_FILTER_DEBUGGER_HIDDEN))
+ /* Treat STEP_THOUGH the same as HIDDEN */
+ req->modifiers [i].data.filter |= STEP_FILTER_DEBUGGER_STEP_THROUGH;
} else if (mod == MOD_KIND_THREAD_ONLY) {
int id = decode_id (p, &p, end);
return err;
req->modifiers [i].caught = decode_byte (p, &p, end);
req->modifiers [i].uncaught = decode_byte (p, &p, end);
- DEBUG(1, fprintf (log_file, "[dbg] \tEXCEPTION_ONLY filter (%s%s%s).\n", exc_class ? exc_class->name : "all", req->modifiers [i].caught ? ", caught" : "", req->modifiers [i].uncaught ? ", uncaught" : ""));
+ if (CHECK_PROTOCOL_VERSION (2, 25))
+ req->modifiers [i].subclasses = decode_byte (p, &p, end);
+ else
+ req->modifiers [i].subclasses = TRUE;
+ DEBUG(1, fprintf (log_file, "[dbg] \tEXCEPTION_ONLY filter (%s%s%s%s).\n", exc_class ? exc_class->name : "all", req->modifiers [i].caught ? ", caught" : "", req->modifiers [i].uncaught ? ", uncaught" : "", req->modifiers [i].subclasses ? ", include-subclasses" : ""));
if (exc_class) {
req->modifiers [i].data.exc_class = exc_class;