Compare commits

...
Author SHA1 Message Date
Ankit Jain 02f1f54f2d [wasm][debugger] simple cleanup 2020-04-10 12:44:31 -04:00
Ankit Jain 8140399b53 [wasm][debugger] System.Guid is special-cased, so remove it from the
.. allowed list.
2020-04-10 12:44:31 -04:00
Ankit Jain ba27c129e6 [wasm][debugger] Don't box valuetypes for calling ToString()
Co-authored by @vargaz .
2020-04-10 12:44:31 -04:00
Ankit Jain 361d7f340a [wasm][debugger] Special case System.Guid to use
.. `mono_guid_to_string`, instead of calling `ToString()` on it.
2020-04-10 12:44:31 -04:00
Ankit Jain e52df644ab [wasm][debugger] Fix DateTime tests, don't use hardcoded strings for
.. description. Instead, use a `DateTime` object in the test to create
the expected string for the test. This should ensure that the expected
and actual were created in the same environment.
2020-04-10 12:44:30 -04:00
Ankit Jain 9f2c5fdcb7 [wasm][debugger] Show char symbol along with the code
Fixes https://github.com/mono/mono/issues/19381
2020-04-10 12:44:30 -04:00
Ankit Jain 27850f9f8c [wasm][debugger] Invoke all property getters, for some types
- `System.DateTime`
- `System.DateTimeOffset`
- `System.TimeSpan`
2020-04-10 12:44:30 -04:00
Ankit Jain 5bbca1f930 [wasm][debugger] For some types, use ToString() for their ..
.. `description`.

- `System.DateTime`
- `System.DateTimeOffset`
- `System.Decimal`
- `System.TimeSpan`
- `System.Guid`
2020-04-10 12:44:30 -04:00
Ankit Jain ab15ba3d99 [wasm][debugger] Fix up value.description for local vars too
- Local vars, when being enumerated in `mono_wasm_get_variables` don't
have an associated `name`, and so `_fixup_name_value_objects`
*incorrectly* ends up not fixing up the `value.description` field for
them.
2020-04-10 12:44:30 -04:00
5 changed files with 439 additions and 64 deletions

No files matched your search

+127 -14
View File
@@ -42,11 +42,13 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_get_array_value_expanded (int object_id, int
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_obj_var (const char*, guint64);
extern void mono_wasm_add_value_type_unexpanded_var (const char*);
extern void mono_wasm_begin_value_type_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*, guint64);
@@ -67,6 +69,21 @@ static GHashTable *objrefs;
static GHashTable *obj_to_objref;
static int objref_id = 0;
static const char*
all_getters_allowed_class_names[] = {
"System.DateTime",
"System.DateTimeOffset",
"System.TimeSpan"
};
static const char*
to_string_as_descr_names[] = {
"System.DateTime",
"System.DateTimeOffset",
"System.Decimal",
"System.TimeSpan"
};
#define THREAD_TO_INTERNAL(thread) (thread)->internal_thread
static void
@@ -616,6 +633,72 @@ mono_wasm_enum_frames (void)
mono_walk_stack_with_ctx (list_frames, NULL, MONO_UNWIND_NONE, NULL);
}
static char*
invoke_to_string (const char *class_name, MonoClass *klass, gpointer addr)
{
MonoObject *exc;
MonoString *mstr;
char *ret_str;
ERROR_DECL (error);
MonoObject *obj;
// TODO: this is for a specific use case right now,
// (invoke ToString() get a preview/description for *some* types)
// and we don't want to report errors for that.
if (m_class_is_valuetype (klass)) {
MonoMethod *method;
MONO_STATIC_POINTER_INIT (MonoMethod, to_string)
to_string = mono_class_get_method_from_name_checked (mono_get_object_class (), "ToString", 0, METHOD_ATTRIBUTE_VIRTUAL | METHOD_ATTRIBUTE_PUBLIC, error);
mono_error_assert_ok (error);
MONO_STATIC_POINTER_INIT_END (MonoMethod, to_string)
method = mono_class_get_virtual_method (klass, to_string, FALSE, error);
if (!method)
return NULL;
MonoString *mstr = (MonoString*) mono_runtime_try_invoke (method, addr , NULL, &exc, error);
if (exc || !is_ok (error)) {
DEBUG_PRINTF (1, "Failed to invoke ToString for %s\n", class_name);
return NULL;
}
return mono_string_to_utf8_checked_internal (mstr, error);
}
obj = *(MonoObject**)addr;
if (!obj)
return NULL;
mstr = mono_object_try_to_string (obj, &exc, error);
if (exc || !is_ok (error))
return NULL;
ret_str = mono_string_to_utf8_checked_internal (mstr, error);
if (!is_ok (error))
return NULL;
return ret_str;
}
static char*
get_to_string_description (const char* class_name, MonoClass *klass, gpointer addr)
{
if (!class_name || !klass || !addr)
return NULL;
if (strcmp (class_name, "System.Guid") == 0)
return mono_guid_to_string (addr);
for (int i = 0; i < G_N_ELEMENTS (to_string_as_descr_names); i ++) {
if (strcmp (to_string_as_descr_names [i], class_name) == 0) {
return invoke_to_string (class_name, klass, addr);
}
}
return NULL;
}
typedef struct {
int cur_frame;
int target_frame;
@@ -673,6 +756,8 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
mono_wasm_add_number_var (*(guint8*)addr);
break;
case MONO_TYPE_CHAR:
mono_wasm_add_char_var (*(guint16*)addr);
break;
case MONO_TYPE_U2:
mono_wasm_add_number_var (*(guint16*)addr);
break;
@@ -734,7 +819,9 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
} else if (m_class_is_delegate (klass)) {
mono_wasm_add_func_var (class_name, obj_id);
} else {
mono_wasm_add_obj_var (class_name, obj_id);
char *to_string_val = get_to_string_description (class_name, klass, addr);
mono_wasm_add_obj_var (class_name, to_string_val, obj_id);
g_free (to_string_val);
}
g_free (class_name);
break;
@@ -779,12 +866,17 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
mono_wasm_add_enum_var (class_name, enum_members->str, value__);
g_string_free (enum_members, TRUE);
} else if (expandValueType) {
mono_wasm_begin_value_type_var (class_name);
char *to_string_val = get_to_string_description (class_name, klass, addr);
mono_wasm_begin_value_type_var (class_name, to_string_val);
g_free (to_string_val);
// FIXME: isAsyncLocalThis
describe_object_properties_for_klass ((MonoObject*)addr, klass, FALSE, expandValueType);
mono_wasm_end_value_type_var ();
} else {
mono_wasm_add_value_type_unexpanded_var (class_name);
char *to_string_val = get_to_string_description (class_name, klass, addr);
mono_wasm_add_value_type_unexpanded_var (class_name, to_string_val);
g_free (to_string_val);
}
g_free (class_name);
break;
@@ -800,6 +892,17 @@ static gboolean describe_value(MonoType * type, gpointer addr, gboolean expandVa
return TRUE;
}
static gboolean
are_getters_allowed (const char *class_name)
{
for (int i = 0; i < G_N_ELEMENTS (all_getters_allowed_class_names); i ++) {
if (strcmp (class_name, all_getters_allowed_class_names [i]) == 0)
return TRUE;
}
return FALSE;
}
static void
describe_object_properties_for_klass (void *obj, MonoClass *klass, gboolean isAsyncLocalThis, gboolean expandValueType)
{
@@ -810,6 +913,8 @@ describe_object_properties_for_klass (void *obj, MonoClass *klass, gboolean isAs
ERROR_DECL (error);
gboolean is_valuetype;
int pnum;
char *klass_name;
gboolean getters_allowed;
g_assert (klass);
is_valuetype = m_class_is_valuetype(klass);
@@ -841,12 +946,17 @@ describe_object_properties_for_klass (void *obj, MonoClass *klass, gboolean isAs
describe_value (f->type, field_addr, is_valuetype | expandValueType);
}
klass_name = mono_class_full_name (klass);
getters_allowed = are_getters_allowed (klass_name);
iter = NULL;
pnum = 0;
while ((p = mono_class_get_properties (klass, &iter))) {
DEBUG_PRINTF (2, "mono_class_get_properties - %s - %s\n", p->name, p->get->name);
if (p->get->name) { //if get doesn't have name means that doesn't have a getter implemented and we don't want to show value, like VS debug
char *class_name;
MonoObject *res;
MonoObject *exc;
if (isAsyncLocalThis && (p->name[0] != '<' || (p->name[0] == '<' && p->name[1] == '>')))
continue;
@@ -854,14 +964,18 @@ describe_object_properties_for_klass (void *obj, MonoClass *klass, gboolean isAs
sig = mono_method_signature_internal (p->get);
// automatic properties will get skipped
class_name = mono_class_full_name (mono_class_from_mono_type_internal (sig->ret));
mono_wasm_add_string_var (class_name);
g_free (class_name);
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);
g_free (ret_class_name);
continue;
}
#if false // Disabled for now, as we don't want to invoke getters
if (is_valuetype && mono_class_from_mono_type_internal (sig->ret) == klass) {
// Property of the same valuetype, avoid endlessly recursion!
mono_wasm_add_string_var (mono_class_full_name (klass));
mono_wasm_add_getter_var (klass_name);
continue;
}
@@ -874,7 +988,6 @@ describe_object_properties_for_klass (void *obj, MonoClass *klass, gboolean isAs
describe_value (sig->ret, &res, TRUE);
else
describe_value (sig->ret, mono_object_unbox_internal (res), TRUE);
#endif
}
pnum ++;
}
@@ -975,7 +1088,7 @@ describe_non_async_this (InterpFrame *frame, MonoMethod *method)
char *class_name = mono_class_full_name (obj->vtable->klass);
mono_wasm_add_properties_var ("this", -1);
mono_wasm_add_obj_var (class_name, get_object_id(obj));
mono_wasm_add_obj_var (class_name, NULL, get_object_id(obj));
g_free (class_name);
}
}
+161 -33
View File
@@ -235,6 +235,15 @@ namespace DebuggerTests
Assert.True(false, $"Could not find variable '{name}'");
}
JToken CheckSymbol (JToken locals, string name, string value)
{
var l = GetAndAssertObjectWithName (locals, name);
var val = l["value"];
Assert.Equal ("symbol", val ["type"]?.Value<string> ());
Assert.Equal (value, val ["value"]?.Value<string> ());
return l;
}
JToken CheckObject (JToken locals, string name, string class_name, string subtype=null, bool is_null=false) {
var l = GetAndAssertObjectWithName (locals, name);
var val = l["value"];
@@ -251,28 +260,25 @@ namespace DebuggerTests
}
async Task CheckDateTime (JToken locals, string name, DateTime expected)
=> await CheckObjectOnLocals (locals, name,
{
var obj = locals.Where (jt => jt ["name"]?.Value<string> () == name)
.FirstOrDefault ();
Assert.Equal (expected.ToString (), obj ["value"]? ["description"]?.Value<string> ());
await CheckObjectOnLocals (locals, name,
test_fn: (members) => {
// not checking everything
#if false
CheckNumber (members, "Year", expected.Year);
CheckNumber (members, "Month", expected.Month);
CheckNumber (members, "Day", expected.Day);
CheckNumber (members, "Hour", expected.Hour);
CheckNumber (members, "Minute", expected.Minute);
CheckNumber (members, "Second", expected.Second);
#endif
CheckString (members, "Year", "int");
CheckString (members, "Month", "int");
CheckString (members, "Day", "int");
CheckString (members, "Hour", "int");
CheckString (members, "Minute", "int");
CheckString (members, "Second", "int");
// FIXME: check some float properties too
}
);
}
JToken CheckBool (JToken locals, string name, bool expected)
{
@@ -363,6 +369,17 @@ namespace DebuggerTests
}
);
[Fact]
public async Task InspectPrimitiveTypeLocalsAtBreakpointSite () =>
await CheckInspectLocalsAtBreakpointSite (
"dotnet://debugger-test.dll/debugger-test.cs", 143, 2, "PrimitiveTypesTest",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] Math:PrimitiveTypesTest'); }, 1);",
test_fn: (locals) => {
CheckSymbol (locals, "c0", "8364 '€'");
CheckSymbol (locals, "c1", "65 'A'");
}
);
[Fact]
public async Task InspectLocalsWithDelegatesAtBreakpointSite () =>
await CheckInspectLocalsAtBreakpointSite (
@@ -903,18 +920,19 @@ namespace DebuggerTests
}
);
var dt = new DateTime (2021, 2, 3, 4, 6, 7);
// Check ss_local's properties
var ss_local_props = await CompareObjectPropertiesOnFrameLocals (pause_location ["callFrames"][0], "ss_local",
new {
str_member = TString ("set in MethodWithLocalStructs#SimpleStruct#str_member"),
dt = TValueType ("System.DateTime"),
dt = TValueType ("System.DateTime", dt.ToString ()),
gs = TValueType ("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum ("System.DateTimeKind", "Utc")
});
{
// Check ss_local.dt
await CheckDateTime (ss_local_props, "dt", new DateTime (2021, 2, 3, 4, 6, 7));
await CheckDateTime (ss_local_props, "dt", dt);
// Check ss_local.gs
await CheckObjectOnLocals (ss_local_props, "gs",
@@ -947,23 +965,31 @@ namespace DebuggerTests
);
{
await CompareObjectPropertiesFor (vt_local_props, "SimpleStructProperty",
// SimpleStructProperty
dt = new DateTime (2022, 3, 4, 5, 7, 8);
var ssp_props = await CompareObjectPropertiesFor (vt_local_props, "SimpleStructProperty",
new {
str_member = TString ("SimpleStructProperty#string#0#SimpleStruct#str_member"),
dt = TValueType ("System.DateTime"),
dt = TValueType ("System.DateTime", dt.ToString ()),
gs = TValueType ("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum ("System.DateTimeKind", "Utc")
},
label: "vt_local_props.SimpleStructProperty");
await CompareObjectPropertiesFor (vt_local_props, "SimpleStructField",
await CheckDateTime (ssp_props, "dt", dt);
// SimpleStructField
dt = new DateTime (2025, 6, 7, 8, 10, 11);
var ssf_props = await CompareObjectPropertiesFor (vt_local_props, "SimpleStructField",
new {
str_member = TString ("SimpleStructField#string#0#SimpleStruct#str_member"),
dt = TValueType ("System.DateTime"),
dt = TValueType ("System.DateTime", dt.ToString ()),
gs = TValueType ("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum ("System.DateTimeKind", "Local")
},
label: "vt_local_props.SimpleStructField");
await CheckDateTime (ssf_props, "dt", dt);
}
// FIXME: check ss_local.gs.List's members
@@ -996,9 +1022,10 @@ namespace DebuggerTests
}
);
var dt = new DateTime (2025, 6, 7, 8, 10, 11);
var ss_local_as_ss_arg = new {
str_member = TString ("ss_local#SimpleStruct#string#0#SimpleStruct#str_member"),
dt = TValueType ("System.DateTime"),
dt = TValueType ("System.DateTime", dt.ToString ()),
gs = TValueType ("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum ("System.DateTimeKind", "Local")
};
@@ -1014,7 +1041,7 @@ namespace DebuggerTests
{
// Check ss_local.dt
await CheckDateTime (ss_arg_props, "dt", new DateTime (2025, 6, 7, 8, 10, 11));
await CheckDateTime (ss_arg_props, "dt", dt);
// Check ss_local.gs
await CompareObjectPropertiesFor (ss_arg_props, "gs", ss_local_gs);
@@ -1033,7 +1060,7 @@ namespace DebuggerTests
var ss_arg_updated = new {
str_member = TString ("ValueTypesTest#MethodWithStructArgs#updated#ss_arg#str_member"),
dt = TValueType ("System.DateTime"),
dt = TValueType ("System.DateTime", dt.ToString ()),
gs = TValueType ("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum ("System.DateTimeKind", "Utc")
};
@@ -1048,6 +1075,8 @@ namespace DebuggerTests
List = TObject ("System.Collections.Generic.List<System.DateTime>"),
Options = TEnum ("DebuggerTests.Options", "Option1")
});
await CheckDateTime (ss_arg_props, "dt", dt);
}
// Check locals on previous frame, same as earlier in this test
@@ -1056,7 +1085,7 @@ namespace DebuggerTests
{
// Check ss_local.dt
await CheckDateTime (ss_arg_props, "dt", new DateTime (2025, 6, 7, 8, 10, 11));
await CheckDateTime (ss_arg_props, "dt", dt);
// Check ss_local.gs
await CheckObjectOnLocals (ss_arg_props, "gs",
@@ -1115,18 +1144,19 @@ namespace DebuggerTests
},
"locals#0");
var dt = new DateTime (2021, 2, 3, 4, 6, 7);
// Check ss_local's properties
var ss_local_props = await CompareObjectPropertiesOnFrameLocals (pause_location ["callFrames"][0], "ss_local",
new {
str_member = TString ("set in MethodWithLocalStructsStaticAsync#SimpleStruct#str_member"),
dt = TValueType ("System.DateTime"),
dt = TValueType ("System.DateTime", dt.ToString ()),
gs = TValueType ("DebuggerTests.ValueTypesTest.GenericStruct<System.DateTime>"),
Kind = TEnum ("System.DateTimeKind", "Utc")
});
{
// Check ss_local.dt
await CheckDateTime (ss_local_props, "dt", new DateTime (2021, 2, 3, 4, 6, 7));
await CheckDateTime (ss_local_props, "dt", dt);
// Check ss_local.gs
await CompareObjectPropertiesFor (ss_local_props, "gs",
@@ -1172,7 +1202,7 @@ namespace DebuggerTests
Color = TEnum ("DebuggerTests.RGB", Color),
//PointWithCustomGetter = TValueType ("DebuggerTests.Point")
// only automatic properties are supported currently!
PointWithCustomGetter = TString ("DebuggerTests.Point")
PointWithCustomGetter = TSymbol ("DebuggerTests.Point { get; }")
};
static Func<int, int, string, string, object> TPoint = (X, Y, Id, Color) => new {
@@ -1650,6 +1680,101 @@ namespace DebuggerTests
});
}
[Theory]
[InlineData (123, 3, "MethodWithLocalsForToStringTest", false, false)]
[InlineData (133, 3, "MethodWithArgumentsForToStringTest", true, false)]
[InlineData (175, 3, "MethodWithArgumentsForToStringTestAsync", true, true)]
[InlineData (165, 3, "MethodWithArgumentsForToStringTestAsync", false, true)]
public async Task InspectLocalsForToStringDescriptions (int line, int col, string method_name, bool call_other, bool invoke_async)
{
var insp = new Inspector ();
//Collect events
var scripts = SubscribeToScripts(insp);
string entry_method_name = $"[debugger-test] DebuggerTests.ValueTypesTest:MethodWithLocalsForToStringTest{(invoke_async ? "Async" : String.Empty)}";
int frame_idx = 0;
await Ready();
await insp.Ready (async (cli, token) => {
ctx = new DebugTestContext (cli, insp, token, scripts);
var debugger_test_loc = "dotnet://debugger-test.dll/debugger-valuetypes-test.cs";
await SetBreakpoint (debugger_test_loc, line, col);
var eval_expr = "window.setTimeout(function() {"
+ (invoke_async ? "invoke_static_method_async (" : "invoke_static_method (")
+ $"'{entry_method_name}',"
+ (call_other ? "true" : "false")
+ "); }, 1);";
Console.WriteLine ($"{eval_expr}");
var pause_location = await EvaluateAndCheck (eval_expr, debugger_test_loc, line, col, invoke_async ? "MoveNext" : method_name);
var dt0 = new DateTime (2020, 1, 2, 3, 4, 5);
var dt1 = new DateTime (2010, 5, 4, 3, 2, 1);
var ts = dt0 - dt1;
var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0));
var frame_locals = await CheckLocalsOnFrame (pause_location ["callFrames"][frame_idx],
new {
call_other = TBool (call_other),
dt0 = TValueType ("System.DateTime", dt0.ToString ()),
dt1 = TValueType ("System.DateTime", dt1.ToString ()),
dto = TValueType ("System.DateTimeOffset", dto.ToString ()),
ts = TValueType ("System.TimeSpan", ts.ToString ()),
dec = TValueType ("System.Decimal", "123987123"),
guid = TValueType ("System.Guid", "3D36E07E-AC90-48C6-B7EC-A481E289D014"),
dts = TArray ("System.DateTime[]"),
obj = TObject ("DebuggerTests.ClassForToStringTests"),
sst = TObject ("DebuggerTests.StructForToStringTests")
},
"locals#0");
var dts_0 = new DateTime (1983, 6, 7, 5, 6, 10);
var dts_1 = new DateTime (1999, 10, 15, 1, 2, 3);
var dts_elements = await CheckObjectOnLocals (frame_locals, "dts");
await CheckDateTime (dts_elements, "[0]", dts_0);
await CheckDateTime (dts_elements, "[1]", dts_1);
// TimeSpan
await CompareObjectPropertiesFor (frame_locals, "ts",
new {
Days = TNumber (3530),
Minutes = TNumber (2),
Seconds = TNumber (4),
}, "ts_props", num_fields: 12);
// DateTimeOffset
await CompareObjectPropertiesFor (frame_locals, "dto",
new {
Day = TNumber (2),
Year = TNumber (2020),
DayOfWeek = TEnum ("System.DayOfWeek", "Thursday")
}, "dto_props", num_fields: 22);
var DT = new DateTime (2004, 10, 15, 1, 2, 3);
var DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0));
var obj_props = await CompareObjectPropertiesFor (frame_locals, "obj",
new {
DT = TValueType ("System.DateTime", DT.ToString ()),
DTO = TValueType ("System.DateTimeOffset", DTO.ToString ()),
TS = TValueType ("System.TimeSpan", ts.ToString ()),
Dec = TValueType ("System.Decimal", "1239871"),
Guid = TValueType ("System.Guid", "3D36E07E-AC90-48C6-B7EC-A481E289D014")
}, "obj_props");
DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0));
var sst_props = await CompareObjectPropertiesFor (frame_locals, "sst",
new {
DT = TValueType ("System.DateTime", DT.ToString ()),
DTO = TValueType ("System.DateTimeOffset", DTO.ToString ()),
TS = TValueType ("System.TimeSpan", ts.ToString ()),
Dec = TValueType ("System.Decimal", "1239871"),
Guid = TValueType ("System.Guid", "3D36E07E-AC90-48C6-B7EC-A481E289D014")
}, "sst_props");
});
}
[Fact]
public async Task EvaluateThisProperties ()
{
@@ -2010,11 +2135,11 @@ namespace DebuggerTests
}
// Find an object with @name in the *frame*, *fetch* the object, and check against @o
async Task<JToken> CompareObjectPropertiesOnFrameLocals (JToken locals, string name, object o, string label = null) {
async Task<JToken> CompareObjectPropertiesOnFrameLocals (JToken locals, string name, object o, string label = null, int num_fields = -1) {
var obj_props = await CheckObjectOnFrameLocals (locals, name, (jt) => {});
try {
if (o != null)
await CheckProps (obj_props, o, label);
await CheckProps (obj_props, o, label, num_fields);
} catch {
Console.WriteLine ($"CheckObjectOnFrameLocals failed for locals: {obj_props}");
throw;
@@ -2029,14 +2154,14 @@ namespace DebuggerTests
}
// Find an object with @name, *fetch* the object, and check against @o
async Task<JToken> CompareObjectPropertiesFor (JToken locals, string name, object o, string label = null)
async Task<JToken> CompareObjectPropertiesFor (JToken locals, string name, object o, string label = null, int num_fields = -1)
{
if (label == null)
label = name;
var props = await CheckObjectOnLocals (locals, name, (jt) => {});
try {
if (o != null)
await CheckProps (props, o, label);
await CheckProps (props, o, label, num_fields);
return props;
} catch {
Console.WriteLine ($"CheckObjectOnFrameLocals failed for locals: {props}");
@@ -2044,7 +2169,7 @@ namespace DebuggerTests
}
}
async Task<JToken> CheckObjectOnLocals (JToken locals, string name, Action<JToken> test_fn)
async Task<JToken> CheckObjectOnLocals (JToken locals, string name, Action<JToken> test_fn = null)
{
var obj = locals.Where (jt => jt ["name"]?.Value<string> () == name)
.FirstOrDefault ();
@@ -2121,16 +2246,16 @@ namespace DebuggerTests
static JObject TNumber (int value) =>
JObject.FromObject (new { type = "number", value = @value.ToString (), description = value.ToString () });
static JObject TValueType (string className, object members = null) =>
JObject.FromObject (new { type = "object", isValueType = true, className = className, description = className });
static JObject TValueType (string className, string description = null, object members = null) =>
JObject.FromObject (new { type = "object", isValueType = true, className = className, description = description ?? className });
static JObject TEnum (string className, string descr, object members = null) =>
JObject.FromObject (new { type = "object", isEnum = true, className = className, description = descr });
static JObject TObject (string className, bool is_null = false) =>
static JObject TObject (string className, string description = null, bool is_null = false) =>
is_null
? JObject.FromObject (new { type = "object", className = className, description = className, subtype = is_null ? "null" : null })
: JObject.FromObject (new { type = "object", className = className, description = className });
? JObject.FromObject (new { type = "object", className = className, description = description ?? className, subtype = is_null ? "null" : null })
: JObject.FromObject (new { type = "object", className = className, description = description ?? className });
static JObject TArray (string className)
=> JObject.FromObject (new { type = "object", className = className, description = className, subtype = "array" });
@@ -2138,6 +2263,9 @@ namespace DebuggerTests
static JObject TBool (bool value)
=> JObject.FromObject (new { type = "boolean", value = @value, description = @value ? "true" : "false" });
static JObject TSymbol (string value)
=> JObject.FromObject (new { type = "symbol", value = @value, description = @value });
//TODO add tests covering basic stepping behavior as step in/out/over
}
+10
View File
@@ -135,6 +135,16 @@ public class Math { //Only append content to this class as the test suite depend
public SimpleStruct SimpleStructProperty { get; set; }
}
public static void PrimitiveTypesTest ()
{
char c0 = '€';
char c1 = 'A';
// TODO: other types!
// just trying to ensure vars don't get optimized out
if (c0 < 32 || c1 > 32)
Console.WriteLine ($"{c0}, {c1}");
}
struct SimpleStruct
{
public DateTime dt;
+103
View File
@@ -91,6 +91,109 @@ namespace DebuggerTests {
public DateTime DT { get; set; }
public RGB RGB;
public static void MethodWithLocalsForToStringTest (bool call_other)
{
var dt0 = new DateTime (2020, 1, 2, 3, 4, 5);
var dt1 = new DateTime (2010, 5, 4, 3, 2, 1);
var ts = dt0 - dt1;
var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0));
decimal dec = 123987123;
var guid = new Guid ("3d36e07e-ac90-48c6-b7ec-a481e289d014");
var dts = new DateTime [] {
new DateTime (1983, 6, 7, 5, 6, 10),
new DateTime (1999, 10, 15, 1, 2, 3)
};
var obj = new ClassForToStringTests {
DT = new DateTime (2004, 10, 15, 1, 2, 3),
DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0)),
TS = ts,
Dec = 1239871,
Guid = guid
};
var sst = new StructForToStringTests {
DT = new DateTime (2004, 10, 15, 1, 2, 3),
DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0)),
TS = ts,
Dec = 1239871,
Guid = guid
};
Console.WriteLine ($"MethodWithLocalsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
if (call_other)
MethodWithArgumentsForToStringTest (call_other, dt0, dt1, ts, dto, dec, guid, dts, obj, sst);
}
static void MethodWithArgumentsForToStringTest (
bool call_other, // not really used, just to help with using common code in the tests
DateTime dt0, DateTime dt1, TimeSpan ts, DateTimeOffset dto, decimal dec,
Guid guid, DateTime[] dts, ClassForToStringTests obj, StructForToStringTests sst)
{
Console.WriteLine ($"MethodWithArgumentsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
}
public static async Task MethodWithLocalsForToStringTestAsync (bool call_other)
{
var dt0 = new DateTime (2020, 1, 2, 3, 4, 5);
var dt1 = new DateTime (2010, 5, 4, 3, 2, 1);
var ts = dt0 - dt1;
var dto = new DateTimeOffset (dt0, new TimeSpan(4, 5, 0));
decimal dec = 123987123;
var guid = new Guid ("3d36e07e-ac90-48c6-b7ec-a481e289d014");
var dts = new DateTime [] {
new DateTime (1983, 6, 7, 5, 6, 10),
new DateTime (1999, 10, 15, 1, 2, 3)
};
var obj = new ClassForToStringTests {
DT = new DateTime (2004, 10, 15, 1, 2, 3),
DTO = new DateTimeOffset (dt0, new TimeSpan(2, 14, 0)),
TS = ts,
Dec = 1239871,
Guid = guid
};
var sst = new StructForToStringTests {
DT = new DateTime (2004, 10, 15, 1, 2, 3),
DTO = new DateTimeOffset (dt0, new TimeSpan (3, 15, 0)),
TS = ts,
Dec = 1239871,
Guid = guid
};
Console.WriteLine ($"MethodWithLocalsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
if (call_other)
await MethodWithArgumentsForToStringTestAsync (call_other, dt0, dt1, ts, dto, dec, guid, dts, obj, sst);
}
static async Task MethodWithArgumentsForToStringTestAsync (
bool call_other, // not really used, just to help with using common code in the tests
DateTime dt0, DateTime dt1, TimeSpan ts, DateTimeOffset dto, decimal dec,
Guid guid, DateTime[] dts, ClassForToStringTests obj, StructForToStringTests sst)
{
Console.WriteLine ($"MethodWithArgumentsForToStringTest: {dt0}, {dt1}, {ts}, {dec}, {guid}, {dts[0]}, {obj.DT}, {sst.DT}");
}
}
class ClassForToStringTests
{
public DateTime DT;
public DateTimeOffset DTO;
public TimeSpan TS;
public decimal Dec;
public Guid Guid;
}
struct StructForToStringTests
{
public DateTime DT;
public DateTimeOffset DTO;
public TimeSpan TS;
public decimal Dec;
public Guid Guid;
}
public enum RGB
+38 -17
View File
@@ -87,27 +87,28 @@ var MonoSupportLib = {
_fixup_name_value_objects: function (var_list) {
var out_list = [];
var _fixup_value = function (value) {
if (value != null && value != undefined) {
var descr = value.description;
if (descr == null || descr == undefined)
value.description = '' + value.value;
}
return value;
};
var i = 0;
while (i < var_list.length) {
var o = var_list [i];
var name = o.name;
if (name == null || name == undefined) {
i ++;
o.value = _fixup_value(o.value);
out_list.push (o);
continue;
}
if (i + 1 < var_list.length) {
var value = var_list [i+1].value;
if (value != null && value != undefined) {
var descr = value.description;
if (descr == null || descr == undefined)
value.description = '' + value.value;
o.value = value;
}
}
if (i + 1 < var_list.length)
o.value = _fixup_value(var_list[i + 1].value);
out_list.push (o);
i += 2;
@@ -449,6 +450,15 @@ var MonoSupportLib = {
});
},
mono_wasm_add_char_var: function(var_value) {
MONO.var_info.push({
value: {
type: "symbol",
value: `${var_value} '${String.fromCharCode (var_value)}'`
}
});
},
mono_wasm_add_number_var: function(var_value) {
MONO.var_info.push({
value: {
@@ -469,13 +479,13 @@ var MonoSupportLib = {
MONO._async_method_objectId = objectId;
},
mono_wasm_begin_value_type_var: function(className) {
mono_wasm_begin_value_type_var: function(className, toString) {
fixed_class_name = MONO._mono_csharp_fixup_class_name(Module.UTF8ToString (className));
var vt_obj = {
value: {
type: "object",
className: fixed_class_name,
description: fixed_class_name,
description: (toString == 0 ? fixed_class_name : Module.UTF8ToString (toString)),
// objectId will be generated by MonoProxy
expanded: true,
isValueType: true,
@@ -504,13 +514,13 @@ var MonoSupportLib = {
}
},
mono_wasm_add_value_type_unexpanded_var: function (className) {
mono_wasm_add_value_type_unexpanded_var: function (className, toString) {
fixed_class_name = MONO._mono_csharp_fixup_class_name(Module.UTF8ToString (className));
MONO.var_info.push({
value: {
type: "object",
className: fixed_class_name,
description: fixed_class_name,
description: (toString == 0 ? fixed_class_name : Module.UTF8ToString (toString)),
// objectId added when enumerating object's properties
expanded: false,
isValueType: true
@@ -562,7 +572,18 @@ var MonoSupportLib = {
});
},
mono_wasm_add_obj_var: function(className, objectId) {
mono_wasm_add_getter_var: function(className) {
var value = `${Module.UTF8ToString (className)} { get; }`;
MONO.var_info.push({
value: {
type: "symbol",
value: value,
description: value
}
});
},
mono_wasm_add_obj_var: function(className, toString, objectId) {
if (objectId == 0) {
MONO.mono_wasm_add_null_var (className);
return;
@@ -573,7 +594,7 @@ var MonoSupportLib = {
value: {
type: "object",
className: fixed_class_name,
description: fixed_class_name,
description: (toString == 0 ? fixed_class_name : Module.UTF8ToString (toString)),
objectId: "dotnet:object:"+ objectId,
}
});