Skip to content

Commit

Permalink
[wasm][debugger] Show pointer type+address (#34934)
Browse files Browse the repository at this point in the history
Co-authored-by: radical <radical@users.noreply.github.com>
  • Loading branch information
monojenkins and radical authored Apr 17, 2020
1 parent 2d1f7b0 commit ce416f4
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions src/mono/mono/mini/mini-wasm-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,16 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_get_array_value_expanded (int object_id, int
//JS functions imported that we use
extern void mono_wasm_add_frame (int il_offset, int method_token, const char *assembly_name);
extern void mono_wasm_fire_bp (void);
extern void mono_wasm_add_bool_var (gint8);
extern void mono_wasm_add_char_var (double);
extern void mono_wasm_add_number_var (double);
extern void mono_wasm_add_string_var (const char*);
extern void mono_wasm_add_getter_var (const char*);
extern void mono_wasm_add_obj_var (const char*, const char*, guint64);
extern void mono_wasm_add_value_type_unexpanded_var (const char*, const char*);
extern void mono_wasm_begin_value_type_var (const char*, const char*);
extern void mono_wasm_end_value_type_var (void);
extern void mono_wasm_add_enum_var (const char*, const char*, guint64);
extern void mono_wasm_add_func_var (const char*, const char*, guint64);
extern void mono_wasm_add_symbol_var (const char*);
extern void mono_wasm_add_array_var (const char*, guint64);
extern void mono_wasm_add_properties_var (const char*, gint32);
extern void mono_wasm_add_array_item (int);
extern void mono_wasm_set_is_async_method (guint64);
extern void mono_wasm_add_typed_value (const char *type, const char *str_value, int int_value);

G_END_DECLS

Expand Down Expand Up @@ -770,51 +764,64 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
ERROR_DECL (error);
switch (type->type) {
case MONO_TYPE_BOOLEAN:
mono_wasm_add_bool_var (*(gint8*)addr);
mono_wasm_add_typed_value ("bool", NULL, *(gint8*)addr);
break;
case MONO_TYPE_I1:
mono_wasm_add_number_var (*(gint8*)addr);
mono_wasm_add_typed_value ("number", NULL, *(gint8*)addr);
break;
case MONO_TYPE_U1:
mono_wasm_add_number_var (*(guint8*)addr);
mono_wasm_add_typed_value ("number", NULL, *(guint8*)addr);
break;
case MONO_TYPE_CHAR:
mono_wasm_add_char_var (*(guint16*)addr);
mono_wasm_add_typed_value ("char", NULL, *(guint16*)addr);
break;
case MONO_TYPE_U2:
mono_wasm_add_number_var (*(guint16*)addr);
mono_wasm_add_typed_value ("number", NULL, *(guint16*)addr);
break;
case MONO_TYPE_I2:
mono_wasm_add_number_var (*(gint16*)addr);
mono_wasm_add_typed_value ("number", NULL, *(gint16*)addr);
break;
case MONO_TYPE_I4:
case MONO_TYPE_I:
mono_wasm_add_number_var (*(gint32*)addr);
mono_wasm_add_typed_value ("number", NULL, *(gint32*)addr);
break;
case MONO_TYPE_U4:
case MONO_TYPE_U:
mono_wasm_add_number_var (*(guint32*)addr);
mono_wasm_add_typed_value ("number", NULL, *(guint32*)addr);
break;
case MONO_TYPE_I8:
mono_wasm_add_number_var (*(gint64*)addr);
mono_wasm_add_typed_value ("number", NULL, *(gint64*)addr);
break;
case MONO_TYPE_U8:
mono_wasm_add_number_var (*(guint64*)addr);
mono_wasm_add_typed_value ("number", NULL, *(guint64*)addr);
break;
case MONO_TYPE_R4:
mono_wasm_add_number_var (*(float*)addr);
mono_wasm_add_typed_value ("number", NULL, *(float*)addr);
break;
case MONO_TYPE_R8:
mono_wasm_add_number_var (*(double*)addr);
mono_wasm_add_typed_value ("number", NULL, *(double*)addr);
break;
case MONO_TYPE_PTR:
case MONO_TYPE_FNPTR: {
char *class_name = mono_type_full_name (type);
const void *val = *(const void **)addr;
char *val_str = g_strdup_printf ("(%s) %p", class_name, val);

mono_wasm_add_typed_value ("pointer", val_str, (guint32)val);

g_free (val_str);
g_free (class_name);
break;
}

case MONO_TYPE_STRING: {
MonoString *str_obj = *(MonoString **)addr;
if (!str_obj) {
mono_wasm_add_string_var (NULL);
mono_wasm_add_typed_value ("string", NULL, 0);
} else {
char *str = mono_string_to_utf8_checked_internal (str_obj, error);
mono_error_assert_ok (error); /* FIXME report error */
mono_wasm_add_string_var (str);
mono_wasm_add_typed_value ("string", str, 0);
g_free (str);
}
break;
Expand All @@ -838,7 +845,7 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
int obj_id = get_object_id (obj);

if (type-> type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY) {
mono_wasm_add_array_var(class_name, obj_id);
mono_wasm_add_typed_value ("array", class_name, obj_id);
} else if (m_class_is_delegate (klass) || (type->type == MONO_TYPE_GENERICINST && m_class_is_delegate (type->data.generic_class->container_class))) {
MonoMethod *method;

Expand Down Expand Up @@ -924,7 +931,7 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
default: {
char *type_name = mono_type_full_name (type);
char *msg = g_strdup_printf("can't handle type %s [%p, %x]", type_name, type, type->type);
mono_wasm_add_string_var (msg);
mono_wasm_add_typed_value ("string", msg, 0);
g_free (msg);
g_free (type_name);
}
Expand Down Expand Up @@ -1007,15 +1014,15 @@ describe_object_properties_for_klass (void *obj, MonoClass *klass, gboolean isAs
if (!getters_allowed) {
// not allowed to call the getter here
char *ret_class_name = mono_class_full_name (mono_class_from_mono_type_internal (sig->ret));
mono_wasm_add_getter_var (ret_class_name);
mono_wasm_add_typed_value ("getter", ret_class_name, 0);
g_free (ret_class_name);

continue;
}

if (is_valuetype && mono_class_from_mono_type_internal (sig->ret) == klass) {
// Property of the same valuetype, avoid endlessly recursion!
mono_wasm_add_getter_var (klass_name);
mono_wasm_add_typed_value ("getter", klass_name, 0);
continue;
}

Expand Down

0 comments on commit ce416f4

Please sign in to comment.