Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
}

[Obsolete("OffsetToStringData has been deprecated. Use string.GetPinnableReference() instead.")]
public static int OffsetToStringData
{
[Intrinsic]
get => OffsetToStringData;
}
public static int OffsetToStringData => string.OFFSET_TO_STRING;

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int InternalGetHashCode(object? o);
Expand Down
6 changes: 6 additions & 0 deletions src/mono/System.Private.CoreLib/src/System/String.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public static string IsInterned(string str)
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern string InternalIntern(string str);

#if TARGET_64BIT
internal const int OFFSET_TO_STRING = 20;
#else
internal const int OFFSET_TO_STRING = 12;
#endif

// TODO: Should be pointing to Buffer instead
#region Runtime method-to-ir dependencies

Expand Down
193 changes: 133 additions & 60 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -3812,7 +3812,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
default:
g_assert_not_reached ();
}
#ifdef HOST_WASI
#ifdef HOST_WASI
resumed_from_wasi = FALSE;
while (suspend_policy != SUSPEND_POLICY_NONE && !resumed_from_wasi)
{
Expand Down Expand Up @@ -4147,7 +4147,14 @@ jit_end (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)
dbg_unlock ();

if (assembly) {
process_profiler_event (EVENT_KIND_ASSEMBLY_LOAD, assembly);
DebuggerTlsData *tls;
tls = (DebuggerTlsData *)mono_native_tls_get_value (debugger_tls_id);
if (tls->invoke == NULL) {
process_profiler_event (EVENT_KIND_ASSEMBLY_LOAD, assembly);
} else {
assembly_load(prof, assembly); //send later
break;
}
} else {
break;
}
Expand Down Expand Up @@ -5068,20 +5075,16 @@ buffer_add_info_for_null_value (Buffer* buf, MonoType* t, MonoDomain* domain)
{
buffer_add_byte (buf, t->type);
switch (t->type) {
case MONO_TYPE_CLASS:
case MONO_TYPE_STRING:
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (t));
break;
case MONO_TYPE_SZARRAY:
case MONO_TYPE_ARRAY:
buffer_add_byte (buf, m_class_get_byval_arg (m_class_get_element_class (mono_class_from_mono_type_internal (t)))->type);
buffer_add_int (buf, m_class_get_rank (mono_class_from_mono_type_internal (t)));
if (m_class_get_byval_arg (m_class_get_element_class (mono_class_from_mono_type_internal (t)))->type == MONO_TYPE_CLASS)
buffer_add_typeid (buf, domain, m_class_get_element_class (mono_class_from_mono_type_internal (t)));
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (t));
break;
default:
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (t));
case MONO_TYPE_SZARRAY:
case MONO_TYPE_ARRAY:
buffer_add_byte (buf, m_class_get_byval_arg (m_class_get_element_class (mono_class_from_mono_type_internal (t)))->type);
buffer_add_int (buf, m_class_get_rank (mono_class_from_mono_type_internal (t)));
if (m_class_get_byval_arg (m_class_get_element_class (mono_class_from_mono_type_internal (t)))->type == MONO_TYPE_CLASS)
buffer_add_typeid (buf, domain, m_class_get_element_class (mono_class_from_mono_type_internal (t)));
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (t));
break;
default:
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (t));
}
}
/*
Expand All @@ -5098,6 +5101,9 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
MonoObject *obj;
gboolean boxed_vtype = FALSE;

if (CHECK_ICORDBG (TRUE))
buffer_add_byte (buf, !!m_type_is_byref (t));

if (m_type_is_byref (t)) {
if (!(*(void**)addr)) {
/* This can happen with compiler generated locals */
Expand Down Expand Up @@ -5298,6 +5304,8 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
if (mono_vtype_get_field_addr (addr, f) == addr && mono_class_from_mono_type_internal (t) == mono_class_from_mono_type_internal (f->type) && !boxed_vtype) //to avoid infinite recursion
{
gssize val = *(gssize*)addr;
if (CHECK_ICORDBG (TRUE))
buffer_add_byte (buf, !!m_type_is_byref (f->type));
buffer_add_byte (buf, MONO_TYPE_PTR);
buffer_add_long (buf, val);
if (CHECK_PROTOCOL_VERSION(2, 46))
Expand Down Expand Up @@ -7097,6 +7105,8 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
minor_version = decode_int (p, &p, end);
if (p < end)
using_icordbg = decode_byte (p, &p, end);
if (using_icordbg)
mono_de_set_using_icordbg ();
protocol_version_set = TRUE;
PRINT_DEBUG_MSG (1, "[dbg] Protocol version %d.%d, client protocol version %d.%d.\n", MAJOR_VERSION, MINOR_VERSION, major_version, minor_version);
break;
Expand All @@ -7120,7 +7130,7 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
wait_for_suspend ();
break;
case CMD_VM_RESUME:
#ifndef HOST_WASI
#ifndef HOST_WASI
if (suspend_count == 0) {
if (agent_config.defer && !agent_config.suspend)
// Workaround for issue in debugger-libs when running in defer attach mode.
Expand Down Expand Up @@ -7708,7 +7718,7 @@ event_commands (int command, guint8 *p, guint8 *end, Buffer *buf)

if (req->event_kind == EVENT_KIND_BREAKPOINT) {
g_assert (method);

req->info = mono_de_set_breakpoint (method, location, req, error);
if (!is_ok (error)) {
g_free (req);
Expand Down Expand Up @@ -7945,6 +7955,42 @@ domain_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
buffer_add_objid (buf, o);
break;
}
case MDBGPROT_CMD_APPDOMAIN_GET_ARRAY_OR_POINTER_TYPE: {
MonoClass *klass;
domain = decode_domainid (p, &p, end, NULL, &err);
MonoTypeEnum type = decode_int (p, &p, end);
klass = decode_typeid (p, &p, end, NULL, &err);
int rank = decode_int (p, &p, end);
if (type == MONO_TYPE_SZARRAY || type == MONO_TYPE_ARRAY)
klass = mono_class_create_array (klass, rank);
else
return ERR_INVALID_ARGUMENT;
buffer_add_typeid (buf, domain, klass);
break;
}

case MDBGPROT_CMD_APPDOMAIN_CREATE_ARRAY: {
ERROR_DECL (error);
MonoClass *klass;
MonoArray *arr;
domain = decode_domainid (p, &p, end, NULL, &err);
klass = decode_typeid (p, &p, end, NULL, &err);
int rank = decode_int (p, &p, end);
uintptr_t *lengths = g_newa (uintptr_t, rank);
intptr_t *lower_bounds = g_newa (intptr_t, rank);
for (int i = 0 ; i < rank; i++)
{
lengths [i] = decode_int (p, &p, end);
}
for (int i = 0 ; i < rank; i++)
{
lower_bounds [i] = decode_int (p, &p, end);
}
arr = mono_array_new_full_checked (klass, lengths, lower_bounds, error);
buffer_add_objid (buf, (MonoObject*) arr);
break;
}

default:
return ERR_NOT_IMPLEMENTED;
}
Expand Down Expand Up @@ -8287,6 +8333,21 @@ field_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
}
break;
}
case MDBGPROT_CMD_FIELD_GET_TOKEN_AND_TYPE: {
MonoClassField *f = decode_fieldid (p, &p, end, &domain, &err);
if (G_UNLIKELY (!f->type)) {
ERROR_DECL(field_error);
mono_field_resolve_type (f, field_error);
mono_error_cleanup (field_error);
if (!f->type)
return ERR_INVALID_OBJECT;
}
buffer_add_int (buf, mono_class_get_field_token (f));
buffer_add_byte(buf, GINT_TO_UINT8(m_class_is_valuetype (mono_class_from_mono_type_internal (f->type))));
buffer_add_int (buf, f->type->type);
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (f->type));
break;
}
default:
return ERR_NOT_IMPLEMENTED;
}
Expand Down Expand Up @@ -8476,6 +8537,19 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
buffer_add_int (buf, 0);
}
}
if (CHECK_ICORDBG (TRUE))
{
if (type->type == MONO_TYPE_FNPTR)
{
buffer_add_int (buf, 1 + type->data.method->param_count);
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (type->data.method->ret));
for (int j = 0; j < type->data.method->param_count; ++j) {
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal (type->data.method->params[j]));
}
} else {
buffer_add_int (buf, 0);
}
}
break;
}
case CMD_TYPE_GET_METHODS: {
Expand Down Expand Up @@ -8890,44 +8964,9 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
buffer_add_objid (buf, obj);
if (CHECK_ICORDBG (TRUE))
{
buffer_add_byte(buf, m_class_is_valuetype (klass));
if (m_class_is_valuetype (klass))
{
int nfields = 0;
gpointer iter = NULL;
while ((f = mono_class_get_fields_internal (klass, &iter))) {
if (G_UNLIKELY (!f->type)) {
ERROR_DECL(field_error);
mono_field_resolve_type (f, field_error);
mono_error_cleanup (field_error);
if (!f->type)
continue;
}
if (f->type->attrs & FIELD_ATTRIBUTE_STATIC)
continue;
if (mono_field_is_deleted (f))
continue;
nfields ++;
}
buffer_add_int (buf, nfields);

iter = NULL;
while ((f = mono_class_get_fields_internal (klass, &iter))) {
if (G_UNLIKELY (!f->type)) {
ERROR_DECL(field_error);
mono_field_resolve_type (f, field_error);
mono_error_cleanup (field_error);
if (!f->type)
continue;
}
if (f->type->attrs & FIELD_ATTRIBUTE_STATIC)
continue;
if (mono_field_is_deleted (f))
continue;
buffer_add_int (buf, mono_class_get_field_token (f));
buffer_add_byte (buf, f->type->type);
}
}
buffer_add_byte(buf, GINT_TO_UINT8(m_class_is_valuetype (klass)));
buffer_add_int (buf, m_class_get_byval_arg (klass)->type);
buffer_add_typeid (buf, domain, klass);
}
break;
}
Expand Down Expand Up @@ -9007,6 +9046,33 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
buffer_add_byte (buf, m_class_get_rank (klass));
break;
}
case MDBGPROT_CMD_TYPE_GET_FIELD_RVA:
{
gpointer iter = NULL;
int field_token = decode_int (p, &p, end);
while ((f = mono_class_get_fields_internal (klass, &iter))) {
if (mono_class_get_field_token (f) == field_token)
{
if (G_UNLIKELY (!f->type)) {
ERROR_DECL(field_error);
mono_field_resolve_type (f, field_error);
mono_error_cleanup (field_error);
if (!f->type)
continue;
}
if (f->type->attrs & FIELD_ATTRIBUTE_HAS_FIELD_RVA)
{
gint32 count = 0;
const char* arr = mono_get_span_data_from_field (f, f->type, f->type, &count);
m_dbgprot_buffer_add_byte_array (buf, (uint8_t *)arr, count);
err = ERR_NONE;
goto exit;
}
}
}
m_dbgprot_buffer_add_int (buf, 0);
break;
}
default:
err = ERR_NOT_IMPLEMENTED;
goto exit;
Expand Down Expand Up @@ -10186,7 +10252,7 @@ array_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
MonoTypeEnum type = m_class_get_byval_arg (m_class_get_element_class (arr->obj.vtable->klass))->type;
buffer_add_byte(buf, type);
buffer_add_int (buf, m_class_get_rank (arr->obj.vtable->klass));
if (type == MONO_TYPE_CLASS || type == MONO_TYPE_GENERICINST || type == MONO_TYPE_OBJECT)
if (type == MONO_TYPE_CLASS || type == MONO_TYPE_GENERICINST || type == MONO_TYPE_OBJECT || (CHECK_ICORDBG (TRUE) && (type == MONO_TYPE_VALUETYPE || type == MONO_TYPE_PTR)))
{
buffer_add_typeid (buf, arr->obj.vtable->domain, m_class_get_element_class (arr->obj.vtable->klass));
if (CHECK_ICORDBG (TRUE))
Expand Down Expand Up @@ -10385,13 +10451,20 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
case CMD_OBJECT_REF_GET_VALUES_BY_FIELD_TOKEN: {
len = 1;
i = 0;
MonoClass* klass = decode_typeid (p, &p, end, NULL, &err);
int class_token = decode_int (p, &p, end);
int field_token = decode_int (p, &p, end);
gpointer iter = NULL;

while ((f = mono_class_get_fields_internal (klass, &iter))) {
if (mono_class_get_field_token (f) == field_token)
for (k = obj_type; k; k = m_class_get_parent (k)) {
if (m_class_get_type_token (k) == class_token) {
break;
}
}

while ((f = mono_class_get_fields_internal (k, &iter))) {
if (mono_class_get_field_token (f) == field_token) {
goto get_field_value;
}
}
goto invalid_fieldid;
}
Expand Down
28 changes: 24 additions & 4 deletions src/mono/mono/component/debugger-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static DebuggerEngineCallbacks rt_callbacks;
static int log_level;
static FILE *log_file;

static bool using_icordbg = FALSE;

/*
* Locking
Expand Down Expand Up @@ -160,6 +161,19 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo
}
}

if (!it_has_sp && using_icordbg)
{
mono_seq_point_iterator_init (&it, seq_points);
while (mono_seq_point_iterator_next (&it)) {
if (it.seq_point.il_offset != METHOD_ENTRY_IL_OFFSET &&
it.seq_point.il_offset != METHOD_EXIT_IL_OFFSET &&
it.seq_point.il_offset > bp->il_offset) {
it_has_sp = TRUE;
break;
}
}
}

if (!it_has_sp) {
char *s = g_strdup_printf ("Unable to insert breakpoint at %s:%ld", mono_method_full_name (jinfo_get_method (ji), TRUE), bp->il_offset);

Expand Down Expand Up @@ -581,10 +595,10 @@ ss_req_cleanup (void)
void
mono_de_start_single_stepping (void)
{
int val = mono_atomic_inc_i32 (&ss_count);
int val = mono_atomic_inc_i32 (&ss_count);

if (val == 1) {
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
mono_arch_start_single_stepping ();
#endif
mini_get_interp_callbacks_api ()->start_single_stepping ();
Expand All @@ -594,10 +608,10 @@ mono_de_start_single_stepping (void)
void
mono_de_stop_single_stepping (void)
{
int val = mono_atomic_dec_i32 (&ss_count);
int val = mono_atomic_dec_i32 (&ss_count);

if (val == 0) {
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
mono_arch_stop_single_stepping ();
#endif
mini_get_interp_callbacks_api ()->stop_single_stepping ();
Expand Down Expand Up @@ -1534,6 +1548,12 @@ mono_de_set_log_level (int level, FILE *file)
log_file = file;
}

void
mono_de_set_using_icordbg ()
{
using_icordbg = TRUE;
}

/*
* mono_de_init:
*
Expand Down
Loading