-/*
- * debugger-agent.c: Soft Debugger back-end module
+/**
+ * \file
+ * Soft Debugger back-end module
*
* Author:
* Zoltan Varga (vargaz@gmail.com)
#endif
#include <mono/metadata/mono-debug.h>
-#include <mono/metadata/mono-debug-debugger.h>
-#include <mono/metadata/debug-mono-symfile.h>
+#include <mono/metadata/debug-internals.h>
#include <mono/metadata/gc-internals.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/threads-types.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/networking.h>
#include <mono/utils/mono-proclib.h>
+#include <mono/utils/w32api.h>
#include "debugger-agent.h"
#include "mini.h"
#include "seq-points.h"
-#include <mono/utils/w32api.h>
+#include "interp/interp.h"
/*
* On iOS we can't use System.Environment.Exit () as it will do the wrong
MonoContext ctx;
MonoDebugMethodJitInfo *jit;
MonoJitInfo *ji;
+ MonoInterpFrameHandle interp_frame;
int flags;
mgreg_t *reg_locations [MONO_MAX_IREGS];
/*
static inline gboolean
is_debugger_thread (void)
{
- return mono_native_thread_id_equals (mono_native_thread_id_get (), debugger_thread_id);
+ MonoInternalThread *internal;
+
+ internal = mono_thread_internal_current ();
+ if (!internal)
+ return FALSE;
+
+ return internal->debugger_thread;
}
static int
if (pos == NULL || pos == address)
return 1;
- *host = (char *)g_malloc (pos - address + 1);
- strncpy (*host, address, pos - address);
- (*host) [pos - address] = '\0';
+ size_t len = pos - address;
+ *host = (char *)g_malloc (len + 1);
+ memcpy (*host, address, len);
+ (*host) [len] = '\0';
*port = atoi (pos + 1);
char **args, **ptr;
char *host;
int port;
- const char *extra;
+ char *extra;
#ifndef MONO_ARCH_SOFT_DEBUG_SUPPORTED
fprintf (stderr, "--debugger-agent is not supported on this platform.\n");
#endif
extra = g_getenv ("MONO_SDB_ENV_OPTIONS");
- if (extra)
+ if (extra) {
options = g_strdup_printf ("%s,%s", options, extra);
+ g_free (extra);
+ }
agent_config.enabled = TRUE;
agent_config.suspend = TRUE;
/* Needed by the hash_table_new_type () call below */
mono_gc_base_init ();
- thread_to_tls = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "thread-to-tls table");
- MONO_GC_REGISTER_ROOT_FIXED (thread_to_tls, MONO_ROOT_SOURCE_DEBUGGER, "thread-to-tls table");
+ thread_to_tls = mono_g_hash_table_new_type ((GHashFunc)mono_object_hash, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "thread-to-tls table");
tid_to_thread = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_DEBUGGER, "tid-to-thread table");
- MONO_GC_REGISTER_ROOT_FIXED (tid_to_thread, MONO_ROOT_SOURCE_DEBUGGER, "tid-to-thread table");
tid_to_thread_obj = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_DEBUGGER, "tid-to-thread object table");
- MONO_GC_REGISTER_ROOT_FIXED (tid_to_thread_obj, MONO_ROOT_SOURCE_DEBUGGER, "tid-to-thread object table");
pending_assembly_loads = g_ptr_array_new ();
domains = g_hash_table_new (mono_aligned_addr_hash, NULL);
static void
start_debugger_thread (void)
{
- debugger_thread_handle = mono_threads_create_thread (debugger_thread, NULL, NULL, NULL);
+ MonoError error;
+ MonoInternalThread *thread;
+
+ thread = mono_thread_create_internal (mono_get_root_domain (), debugger_thread, NULL, MONO_THREAD_CREATE_FLAGS_DEBUGGER, &error);
+ mono_error_assert_ok (&error);
+
+ debugger_thread_handle = mono_threads_open_thread_handle (thread->handle);
g_assert (debugger_thread_handle);
}
{
objrefs = g_hash_table_new_full (NULL, NULL, NULL, free_objref);
obj_to_objref = g_hash_table_new (NULL, NULL);
- suspended_objs = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "suspended objects table");
- MONO_GC_REGISTER_ROOT_FIXED (suspended_objs, MONO_ROOT_SOURCE_DEBUGGER, "suspended objects table");
+ suspended_objs = mono_g_hash_table_new_type ((GHashFunc)mono_object_hash, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "suspended objects table");
}
static void
* SUSPEND/RESUME
*/
+static MonoJitInfo*
+get_top_method_ji (gpointer ip, MonoDomain **domain, gpointer *out_ip)
+{
+ MonoJitInfo *ji;
+
+ if (out_ip)
+ *out_ip = ip;
+
+ ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, domain);
+ if (!ji) {
+ /* Could be an interpreter method */
+
+ MonoLMF *lmf = mono_get_lmf ();
+ MonoInterpFrameHandle *frame;
+
+ g_assert (((guint64)lmf->previous_lmf) & 2);
+ MonoLMFExt *ext = (MonoLMFExt*)lmf;
+
+ g_assert (ext->interp_exit);
+ frame = ext->interp_exit_data;
+ ji = mono_interp_frame_get_jit_info (frame);
+ if (domain)
+ *domain = mono_domain_get ();
+ if (out_ip)
+ *out_ip = mono_interp_frame_get_ip (frame);
+ }
+ return ji;
+}
+
/*
* save_thread_context:
*
* suspended when it returns to managed code, so the parent's ctx should
* remain valid.
*/
+ MonoThreadUnwindState *state = mono_thread_info_get_suspend_state (info);
+
data.last_frame_set = FALSE;
- mono_get_eh_callbacks ()->mono_walk_stack_with_state (get_last_frame, mono_thread_info_get_suspend_state (info), MONO_UNWIND_SIGNAL_SAFE, &data);
+ mono_get_eh_callbacks ()->mono_walk_stack_with_state (get_last_frame, state, MONO_UNWIND_SIGNAL_SAFE, &data);
if (data.last_frame_set) {
gpointer jit_tls = ((MonoThreadInfo*)tls->thread->thread_info)->jit_data;
memcpy (&tls->async_last_frame, &data.last_frame, sizeof (StackFrameInfo));
+ if (data.last_frame.type == FRAME_TYPE_INTERP_TO_MANAGED) {
+ /*
+ * Store the current lmf instead of the parent one, since that
+ * contains the interp exit data.
+ */
+ data.lmf = state->unwind_data [MONO_UNWIND_DATA_LMF];
+ }
+
copy_unwind_state_from_frame_data (&tls->async_state, &data, jit_tls);
copy_unwind_state_from_frame_data (&tls->context, &data, jit_tls);
} else {
DebuggerTlsData *tls = (DebuggerTlsData *)value;
MonoNativeThreadId tid = MONO_UINT_TO_NATIVE_THREAD_ID (thread->tid);
- if (mono_native_thread_id_equals (mono_native_thread_id_get (), tid) || tls->terminated)
+ if (mono_thread_internal_is_current (thread) || tls->terminated)
return;
DEBUG_PRINTF (1, "[%p] Interrupting %p...\n", (gpointer) (gsize) mono_native_thread_id_get (), (gpointer)tid);
return;
}
- ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, NULL);
-
+ ji = get_top_method_ji (ip, NULL, NULL);
+ g_assert (ji);
/* Can't suspend in these methods */
method = jinfo_get_method (ji);
if (method->klass == mono_defaults.string_class && (!strcmp (method->name, "memset") || strstr (method->name, "memcpy")))
{
DebuggerTlsData *tls = (DebuggerTlsData *)value;
- if (!tls->suspended && !tls->terminated)
+ if (!tls->suspended && !tls->terminated && !mono_thread_internal_is_current (tls->thread))
*(int*)user_data = *(int*)user_data + 1;
}
SeqPoint sp;
int flags = 0;
- if (info->type != FRAME_TYPE_MANAGED) {
+ if (info->type != FRAME_TYPE_MANAGED && info->type != FRAME_TYPE_INTERP) {
if (info->type == FRAME_TYPE_DEBUGGER_INVOKE) {
/* Mark the last frame as an invoke frame */
if (ud->frames)
frame->native_offset = info->native_offset;
frame->flags = flags;
frame->ji = info->ji;
+ frame->interp_frame = info->interp_frame;
if (info->reg_locations)
memcpy (frame->reg_locations, info->reg_locations, MONO_MAX_IREGS * sizeof (mgreg_t*));
if (ctx) {
static void
emit_thread_start (gpointer key, gpointer value, gpointer user_data)
{
- if (!mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (GPOINTER_TO_UINT (key)), debugger_thread_id))
- process_profiler_event (EVENT_KIND_THREAD_START, value);
+ g_assert (!mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (GPOINTER_TO_UINT (key)), debugger_thread_id));
+ process_profiler_event (EVENT_KIND_THREAD_START, value);
}
/*
MonoInternalThread *old_thread;
DebuggerTlsData *tls;
- if (mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (tid), debugger_thread_id))
+ if (is_debugger_thread ())
return;
g_assert (mono_native_thread_id_equals (MONO_UINT_TO_NATIVE_THREAD_ID (tid), MONO_UINT_TO_NATIVE_THREAD_ID (thread->tid)));
if (thread) {
DEBUG_PRINTF (1, "[%p] Thread terminated, obj=%p, tls=%p.\n", (gpointer)tid, thread, tls);
- if (mono_native_thread_id_equals (mono_native_thread_id_get (), MONO_UINT_TO_NATIVE_THREAD_ID (tid))
- && !mono_native_tls_get_value (debugger_tls_id)
+ if (mono_thread_internal_is_current (thread) && !mono_native_tls_get_value (debugger_tls_id)
) {
/*
* This can happen on darwin since we deregister threads using pthread dtors.
send_type_load (method->klass);
- if (!result)
+ if (!result && jinfo)
add_pending_breakpoints (method, jinfo);
}
gboolean it_has_sp = FALSE;
if (error)
- mono_error_init (error);
+ error_init (error);
mono_seq_point_iterator_init (&it, seq_points);
while (mono_seq_point_iterator_next (&it)) {
if (it.seq_point.native_offset == SEQ_POINT_NATIVE_OFFSET_DEAD_CODE) {
DEBUG_PRINTF (1, "[dbg] Attempting to insert seq point at dead IL offset %d, ignoring.\n", (int)bp->il_offset);
} else if (count == 0) {
+ if (ji->is_interp) {
+ mono_interp_set_breakpoint (ji, inst->ip);
+ } else {
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
- mono_arch_set_breakpoint (ji, inst->ip);
+ mono_arch_set_breakpoint (ji, inst->ip);
#else
- NOT_IMPLEMENTED;
+ NOT_IMPLEMENTED;
#endif
+ }
}
DEBUG_PRINTF (1, "[dbg] Inserted breakpoint at %s:[il=0x%x,native=0x%x] [%p](%d).\n", mono_method_full_name (jinfo_get_method (ji), TRUE), (int)it.seq_point.il_offset, (int)it.seq_point.native_offset, inst->ip, count);
g_assert (count > 0);
if (count == 1 && inst->native_offset != SEQ_POINT_NATIVE_OFFSET_DEAD_CODE) {
- mono_arch_clear_breakpoint (ji, ip);
+ if (ji->is_interp)
+ mono_interp_clear_breakpoint (ji, ip);
+ else
+ mono_arch_clear_breakpoint (ji, ip);
DEBUG_PRINTF (1, "[dbg] Clear breakpoint at %s [%p].\n", mono_method_full_name (jinfo_get_method (ji), TRUE), ip);
}
#else
MonoJitInfo *ji;
if (error)
- mono_error_init (error);
+ error_init (error);
code = mono_jit_find_compiled_method_with_jit_info (domain, method, &ji);
if (!code) {
/* Might be AOTed code */
mono_class_init (method->klass);
code = mono_aot_get_method_checked (domain, method, &oerror);
- g_assert (code);
- mono_error_assert_ok (&oerror);
- ji = mono_jit_info_table_find (domain, (char *)code);
+ if (code) {
+ mono_error_assert_ok (&oerror);
+ ji = mono_jit_info_table_find (domain, (char *)code);
+ } else {
+ /* Might be interpreted */
+ ji = mono_interp_find_jit_info (domain, method);
+ }
g_assert (ji);
}
- g_assert (code);
insert_breakpoint (seq_points, domain, ji, bp, error);
}
int i;
if (error)
- mono_error_init (error);
+ error_init (error);
// FIXME:
// - suspend/resume the vm to prevent code patching problems
}
}
- MonoDebugMethodAsyncInfo* asyncMethod = mono_debug_lookup_method_async_debug_info (method);
- if (asyncMethod) {
- for (int i = 0; i < asyncMethod->num_awaits; i++)
- {
- if (asyncMethod->yield_offsets[i] == sp->il_offset || asyncMethod->resume_offsets[i] == sp->il_offset) {
- mono_debug_free_method_async_debug_info (asyncMethod);
+ MonoDebugMethodAsyncInfo* async_method = mono_debug_lookup_method_async_debug_info (method);
+ if (async_method) {
+ for (int i = 0; i < async_method->num_awaits; i++) {
+ if (async_method->yield_offsets[i] == sp->il_offset || async_method->resume_offsets[i] == sp->il_offset) {
+ mono_debug_free_method_async_debug_info (async_method);
return FALSE;
}
}
- mono_debug_free_method_async_debug_info (asyncMethod);
+ mono_debug_free_method_async_debug_info (async_method);
}
if (req->size != STEP_SIZE_LINE)
return get_objid (get_this (frame));
}
-static MonoMethod* set_notification_method_cache = NULL;
-
static MonoMethod*
-get_set_notification_method ()
+get_set_notification_method (MonoClass* async_builder_class)
{
- if(set_notification_method_cache != NULL)
- return set_notification_method_cache;
MonoError error;
- MonoClass* async_builder_class = mono_class_load_from_name (mono_defaults.corlib, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder");
GPtrArray* array = mono_class_get_methods_by_name (async_builder_class, "SetNotificationForWaitCompletion", 0x24, FALSE, FALSE, &error);
mono_error_assert_ok (&error);
g_assert (array->len == 1);
- set_notification_method_cache = (MonoMethod *)g_ptr_array_index (array, 0);
+ MonoMethod* set_notification_method = (MonoMethod *)g_ptr_array_index (array, 0);
g_ptr_array_free (array, TRUE);
- return set_notification_method_cache;
+ return set_notification_method;
}
static void
void* args [1];
gboolean arg = TRUE;
args [0] = &arg;
- mono_runtime_invoke_checked (get_set_notification_method(), mono_object_unbox (builder), args, &error);
+ mono_runtime_invoke_checked (get_set_notification_method (builder->vtable->klass), mono_object_unbox (builder), args, &error);
mono_error_assert_ok (&error);
mono_field_set_value (obj, builder_field, mono_object_unbox (builder));
}
}
static void
-process_breakpoint_inner (DebuggerTlsData *tls, gboolean from_signal)
+process_breakpoint (DebuggerTlsData *tls, gboolean from_signal)
{
MonoJitInfo *ji;
guint8 *ip;
ip = (guint8 *)MONO_CONTEXT_GET_IP (ctx);
ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, NULL);
+
+ if (!ji) {
+ /* Interpreter */
+ // FIXME: Pass a flag instead to detect this
+ MonoLMF *lmf = mono_get_lmf ();
+ MonoInterpFrameHandle *frame;
+
+ g_assert (((guint64)lmf->previous_lmf) & 2);
+ MonoLMFExt *ext = (MonoLMFExt*)lmf;
+
+ g_assert (ext->interp_exit);
+ frame = ext->interp_exit_data;
+ ji = mono_interp_frame_get_jit_info (frame);
+ ip = mono_interp_frame_get_ip (frame);
+ }
+
g_assert (ji && !ji->is_trampoline);
method = jinfo_get_method (ji);
/* Compute the native offset of the breakpoint from the ip */
- native_offset = ip - (guint8*)ji->code_start;
+ native_offset = ip - (guint8*)ji->code_start;
/*
* Skip the instruction causing the breakpoint signal.
}
static void
-process_breakpoint (void)
+process_breakpoint_from_signal (void)
{
- process_signal_event (process_breakpoint_inner);
+ process_signal_event (process_breakpoint);
}
static void
* problems, like the original signal is disabled, libgc can't handle altstack, etc.
* So set up the signal context to return to the real breakpoint handler function.
*/
- resume_from_signal_handler (sigctx, process_breakpoint);
+ resume_from_signal_handler (sigctx, process_breakpoint_from_signal);
}
+typedef struct {
+ gboolean found;
+ MonoContext *ctx;
+} UserBreakCbData;
+
static gboolean
-user_break_cb (StackFrameInfo *frame, MonoContext *ctx, gpointer data)
+user_break_cb (StackFrameInfo *frame, MonoContext *ctx, gpointer user_data)
{
+ UserBreakCbData *data = user_data;
+
+ if (frame->type == FRAME_TYPE_INTERP_TO_MANAGED) {
+ data->found = TRUE;
+ return TRUE;
+ }
if (frame->managed) {
- *(MonoContext*)data = *ctx;
+ data->found = TRUE;
+ *data->ctx = *ctx;
return TRUE;
- } else {
- return FALSE;
}
+ return FALSE;
}
/*
MonoContext ctx;
int suspend_policy;
GSList *events;
+ UserBreakCbData data;
+
+ memset (&data, 0, sizeof (UserBreakCbData));
+ data.ctx = &ctx;
/* Obtain a context */
MONO_CONTEXT_SET_IP (&ctx, NULL);
- mono_walk_stack_with_ctx (user_break_cb, NULL, (MonoUnwindOptions)0, &ctx);
- g_assert (MONO_CONTEXT_GET_IP (&ctx) != NULL);
+ mono_walk_stack_with_ctx (user_break_cb, NULL, (MonoUnwindOptions)0, &data);
+ g_assert (data.found);
mono_loader_lock ();
events = create_event_list (EVENT_KIND_USER_BREAK, NULL, NULL, NULL, &suspend_policy);
SeqPoint sp;
MonoSeqPointInfo *info;
- ip = (guint8 *)MONO_CONTEXT_GET_IP (ctx);
-
/* Skip the instruction causing the single step */
if (from_signal)
mono_arch_skip_single_step (ctx);
if (mono_thread_internal_current () != ss_req->thread)
return;
- if (log_level > 0) {
- ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain);
+ ip = (guint8 *)MONO_CONTEXT_GET_IP (ctx);
+ ji = get_top_method_ji (ip, &domain, (gpointer*)&ip);
+ g_assert (ji && !ji->is_trampoline);
+
+ if (log_level > 0) {
DEBUG_PRINTF (1, "[%p] Single step event (depth=%s) at %s (%p)[0x%x], sp %p, last sp %p\n", (gpointer) (gsize) mono_native_thread_id_get (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), (int)((guint8*)MONO_CONTEXT_GET_IP (ctx) - (guint8*)ji->code_start), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp);
}
- ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain);
- g_assert (ji && !ji->is_trampoline);
method = jinfo_get_method (ji);
g_assert (method);
* The ip points to the instruction causing the single step event, which is before
* the offset recorded in the seq point map, so find the next seq point after ip.
*/
- if (!mono_find_next_seq_point_for_native_offset (domain, method, (guint8*)ip - (guint8*)ji->code_start, &info, &sp))
+ if (!mono_find_next_seq_point_for_native_offset (domain, method, (guint8*)ip - (guint8*)ji->code_start, &info, &sp)) {
+ g_assert_not_reached ();
return;
+ }
il_offset = sp.il_offset;
mono_thread_state_init_from_monoctx (&tls->restore_state, ctx);
memcpy (&tls->handler_ctx, ctx, sizeof (MonoContext));
- process_breakpoint_inner (tls, FALSE);
+ process_breakpoint (tls, FALSE);
memcpy (ctx, &tls->restore_state.ctx, sizeof (MonoContext));
memcpy (&tls->restore_state, &orig_restore_state, sizeof (MonoThreadUnwindState));
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
int val = InterlockedIncrement (&ss_count);
- if (val == 1)
+ if (val == 1) {
mono_arch_start_single_stepping ();
+ mono_interp_start_single_stepping ();
+ }
#else
g_assert_not_reached ();
#endif
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
int val = InterlockedDecrement (&ss_count);
- if (val == 0)
+ if (val == 0) {
mono_arch_stop_single_stepping ();
+ mono_interp_stop_single_stepping ();
+ }
#else
g_assert_not_reached ();
#endif
}
}
+static void
+set_interp_var (MonoType *t, gpointer addr, guint8 *val_buf)
+{
+ int size;
+
+ if (t->byref) {
+ addr = *(gpointer*)addr;
+ g_assert (addr);
+ }
+
+ if (MONO_TYPE_IS_REFERENCE (t))
+ size = sizeof (gpointer);
+ else
+ size = mono_class_value_size (mono_class_from_mono_type (t), NULL);
+
+ memcpy (addr, val_buf, size);
+}
+
static void
clear_event_request (int req_id, int etype)
{
case CMD_APPDOMAIN_CREATE_STRING: {
char *s;
MonoString *o;
+ MonoError error;
domain = decode_domainid (p, &p, end, NULL, &err);
if (err != ERR_NONE)
return err;
s = decode_string (p, &p, end);
- o = mono_string_new (domain, s);
+ o = mono_string_new_checked (domain, s, &error);
+ if (!is_ok (&error)) {
+ DEBUG_PRINTF (1, "[dbg] Failed to allocate String object '%s': %s\n", s, mono_error_get_message (&error));
+ mono_error_cleanup (&error);
+ return ERR_INVALID_OBJECT;
+ }
buffer_add_objid (buf, (MonoObject*)o);
break;
}
{
HANDLE_FUNCTION_ENTER();
ErrorCode err = ERR_NONE;
- mono_error_init (error);
+ error_init (error);
MonoReflectionAssemblyHandle o = mono_assembly_get_object_handle (domain, ass, error);
if (MONO_HANDLE_IS_NULL (o)) {
err = ERR_INVALID_OBJECT;
MonoError error;
GPtrArray *array;
- mono_error_init (&error);
+ error_init (&error);
array = mono_class_get_methods_by_name (klass, name, flags & ~BINDING_FLAGS_IGNORE_CASE, (flags & BINDING_FLAGS_IGNORE_CASE) != 0, TRUE, &error);
if (!is_ok (&error)) {
mono_error_cleanup (&error);
// FIXME: Check that the ip change is safe
DEBUG_PRINTF (1, "[dbg] Setting IP to %s:0x%0x(0x%0x)\n", tls->frames [0]->actual_method->name, (int)sp.il_offset, (int)sp.native_offset);
- MONO_CONTEXT_SET_IP (&tls->restore_state.ctx, (guint8*)tls->frames [0]->ji->code_start + sp.native_offset);
+
+ if (tls->frames [0]->ji->is_interp) {
+ MonoJitTlsData *jit_data = ((MonoThreadInfo*)thread->thread_info)->jit_data;
+ mono_interp_set_resume_state (jit_data, NULL, tls->frames [0]->interp_frame, (guint8*)tls->frames [0]->ji->code_start + sp.native_offset);
+ } else {
+ MONO_CONTEXT_SET_IP (&tls->restore_state.ctx, (guint8*)tls->frames [0]->ji->code_start + sp.native_offset);
+ }
break;
}
default:
sig = mono_method_signature (frame->actual_method);
- if (!jit->has_var_info || !mono_get_seq_points (frame->domain, frame->actual_method))
+ if (!(jit->has_var_info || frame->ji->is_interp) || !mono_get_seq_points (frame->domain, frame->actual_method))
/*
* The method is probably from an aot image compiled without soft-debug, variables might be dead, etc.
*/
DEBUG_PRINTF (4, "[dbg] send arg %d.\n", pos);
- g_assert (pos >= 0 && pos < jit->num_params);
+ if (frame->ji->is_interp) {
+ guint8 *addr;
- add_var (buf, jit, sig->params [pos], &jit->params [pos], &frame->ctx, frame->domain, FALSE);
+ addr = mono_interp_frame_get_arg (frame->interp_frame, pos);
+
+ buffer_add_value_full (buf, sig->params [pos], addr, frame->domain, FALSE, NULL);
+ } else {
+ g_assert (pos >= 0 && pos < jit->num_params);
+
+ add_var (buf, jit, sig->params [pos], &jit->params [pos], &frame->ctx, frame->domain, FALSE);
+ }
} else {
MonoDebugLocalsInfo *locals;
pos = locals->locals [pos].index;
mono_debug_free_locals (locals);
}
- g_assert (pos >= 0 && pos < jit->num_locals);
DEBUG_PRINTF (4, "[dbg] send local %d.\n", pos);
- add_var (buf, jit, header->locals [pos], &jit->locals [pos], &frame->ctx, frame->domain, FALSE);
+ if (frame->ji->is_interp) {
+ guint8 *addr;
+
+ addr = mono_interp_frame_get_local (frame->interp_frame, pos);
+
+ buffer_add_value_full (buf, header->locals [pos], addr, frame->domain, FALSE, NULL);
+ } else {
+ g_assert (pos >= 0 && pos < jit->num_locals);
+
+ add_var (buf, jit, header->locals [pos], &jit->locals [pos], &frame->ctx, frame->domain, FALSE);
+ }
}
}
mono_metadata_free_mh (header);
break;
}
case CMD_STACK_FRAME_GET_THIS: {
+ if (frame->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
+ return ERR_ABSENT_INFORMATION;
if (frame->api_method->klass->valuetype) {
if (!sig->hasthis) {
MonoObject *p = NULL;
buffer_add_value (buf, &mono_defaults.object_class->byval_arg, &p, frame->domain);
} else {
- add_var (buf, jit, &frame->actual_method->klass->this_arg, jit->this_var, &frame->ctx, frame->domain, TRUE);
+ if (frame->ji->is_interp) {
+ guint8 *addr;
+
+ addr = mono_interp_frame_get_this (frame->interp_frame);
+
+ buffer_add_value_full (buf, &frame->actual_method->klass->this_arg, addr, frame->domain, FALSE, NULL);
+ } else {
+ add_var (buf, jit, &frame->actual_method->klass->this_arg, jit->this_var, &frame->ctx, frame->domain, TRUE);
+ }
}
} else {
if (!sig->hasthis) {
MonoObject *p = NULL;
buffer_add_value (buf, &frame->actual_method->klass->byval_arg, &p, frame->domain);
} else {
- add_var (buf, jit, &frame->api_method->klass->byval_arg, jit->this_var, &frame->ctx, frame->domain, TRUE);
+ if (frame->ji->is_interp) {
+ guint8 *addr;
+
+ addr = mono_interp_frame_get_this (frame->interp_frame);
+
+ buffer_add_value_full (buf, &frame->api_method->klass->byval_arg, addr, frame->domain, FALSE, NULL);
+ } else {
+ add_var (buf, jit, &frame->api_method->klass->byval_arg, jit->this_var, &frame->ctx, frame->domain, TRUE);
+ }
}
}
break;
MonoError error;
guint8 *val_buf;
MonoType *t;
- MonoDebugVarInfo *var;
+ MonoDebugVarInfo *var = NULL;
+ gboolean is_arg = FALSE;
len = decode_int (p, &p, end);
header = mono_method_get_header_checked (frame->actual_method, &error);
t = sig->params [pos];
var = &jit->params [pos];
+ is_arg = TRUE;
} else {
MonoDebugLocalsInfo *locals;
if (err != ERR_NONE)
return err;
- set_var (t, var, &frame->ctx, frame->domain, val_buf, frame->reg_locations, &tls->restore_state.ctx);
+ if (frame->ji->is_interp) {
+ guint8 *addr;
+
+ if (is_arg)
+ addr = mono_interp_frame_get_arg (frame->interp_frame, pos);
+ else
+ addr = mono_interp_frame_get_local (frame->interp_frame, pos);
+ set_interp_var (t, addr, val_buf);
+ } else {
+ set_var (t, var, &frame->ctx, frame->domain, val_buf, frame->reg_locations, &tls->restore_state.ctx);
+ }
}
mono_metadata_free_mh (header);
break;
t = &frame->actual_method->klass->byval_arg;
/* Checked by the sender */
g_assert (MONO_TYPE_ISSTRUCT (t));
- var = jit->this_var;
- g_assert (var);
val_buf = (guint8 *)g_alloca (mono_class_instance_size (mono_class_from_mono_type (t)));
err = decode_value (t, frame->domain, val_buf, p, &p, end);
if (err != ERR_NONE)
return err;
- set_var (&frame->actual_method->klass->this_arg, var, &frame->ctx, frame->domain, val_buf, frame->reg_locations, &tls->restore_state.ctx);
+ if (frame->ji->is_interp) {
+ guint8 *addr;
+
+ addr = mono_interp_frame_get_this (frame->interp_frame);
+ set_interp_var (&frame->actual_method->klass->this_arg, addr, val_buf);
+ } else {
+ var = jit->this_var;
+ g_assert (var);
+
+ set_var (&frame->actual_method->klass->this_arg, var, &frame->ctx, frame->domain, val_buf, frame->reg_locations, &tls->restore_state.ctx);
+ }
break;
}
default:
debugger_thread_id = mono_native_thread_id_get ();
- MonoThread *thread = mono_thread_attach (mono_get_root_domain ());
- mono_thread_set_name_internal (thread->internal_thread, mono_string_new (mono_get_root_domain (), "Debugger agent"), TRUE, &error);
+ MonoInternalThread *internal = mono_thread_internal_current ();
+ MonoString *str = mono_string_new_checked (mono_domain_get (), "Debugger agent", &error);
+ mono_error_assert_ok (&error);
+ mono_thread_set_name_internal (internal, str, TRUE, FALSE, &error);
mono_error_assert_ok (&error);
- thread->internal_thread->state |= ThreadState_Background;
- thread->internal_thread->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
+ internal->state |= ThreadState_Background;
+ internal->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
if (agent_config.defer) {
if (!wait_for_attach ()) {