mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
[wasm][debugger] Implement support to modify values. (#49557)
* [wasm][debugger] Implement support to modify values. * Apply suggestions from code review Co-authored-by: Larry Ewing <[email protected]> * Adding first test. * Adding more tests, fixing boolean behavior, ignore value change when the new value type is incompatible. * Implement set value on object -> property and attribute. * Fix compilation * Changing what @radical suggested. * Adding tests. * Adding test. * Fix what @radical suggested. * Fix compilation. * Fix what @radical suggested. Co-authored-by: Larry Ewing <[email protected]>
This commit is contained in:
1 parent
d25620b3fe
commit
fc53ee79ef
13 files changed
+794
-44
No files matched your search
@@ -5735,24 +5735,6 @@ set_var (MonoType *t, MonoDebugVarInfo *var, MonoContext *ctx, MonoDomain *domai
|
||||
}
|
||||
}
|
||||
|
||||
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_internal (t), NULL);
|
||||
|
||||
memcpy (addr, val_buf, size);
|
||||
}
|
||||
|
||||
static void
|
||||
clear_event_request (int req_id, int etype)
|
||||
{
|
||||
@@ -9183,7 +9165,9 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
|
||||
addr = (guint8*)mini_get_interp_callbacks ()->frame_get_arg (frame->interp_frame, pos);
|
||||
else
|
||||
addr = (guint8*)mini_get_interp_callbacks ()->frame_get_local (frame->interp_frame, pos);
|
||||
set_interp_var (t, addr, val_buf);
|
||||
err = mono_de_set_interp_var (t, addr, val_buf);
|
||||
if (err != ERR_NONE)
|
||||
return err;
|
||||
} else {
|
||||
set_var (t, var, &frame->ctx, frame->de.domain, val_buf, frame->reg_locations, &tls->restore_state.ctx);
|
||||
}
|
||||
@@ -9214,7 +9198,9 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
|
||||
guint8 *addr;
|
||||
|
||||
addr = (guint8*)mini_get_interp_callbacks ()->frame_get_this (frame->interp_frame);
|
||||
set_interp_var (m_class_get_this_arg (frame->actual_method->klass), addr, val_buf);
|
||||
err = mono_de_set_interp_var (m_class_get_this_arg (frame->actual_method->klass), addr, val_buf);
|
||||
if (err != ERR_NONE)
|
||||
return err;
|
||||
} else {
|
||||
var = jit->this_var;
|
||||
if (!var) {
|
||||
|
||||
@@ -1754,5 +1754,24 @@ get_notify_debugger_of_wait_completion_method (void)
|
||||
return notify_debugger_of_wait_completion_method_cache;
|
||||
}
|
||||
|
||||
DbgEngineErrorCode
|
||||
mono_de_set_interp_var (MonoType *t, gpointer addr, guint8 *val_buf)
|
||||
{
|
||||
int size;
|
||||
|
||||
if (t->byref) {
|
||||
addr = *(gpointer*)addr;
|
||||
if (!addr)
|
||||
return ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
if (MONO_TYPE_IS_REFERENCE (t))
|
||||
size = sizeof (gpointer);
|
||||
else
|
||||
size = mono_class_value_size (mono_class_from_mono_type_internal (t), NULL);
|
||||
|
||||
memcpy (addr, val_buf, size);
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -510,6 +510,8 @@ DbgEngineErrorCode mono_de_ss_create (MonoInternalThread *thread, StepSize size,
|
||||
void mono_de_cancel_ss (SingleStepReq *req);
|
||||
void mono_de_cancel_all_ss (void);
|
||||
|
||||
DbgEngineErrorCode mono_de_set_interp_var (MonoType *t, gpointer addr, guint8 *val_buf);
|
||||
|
||||
gboolean set_set_notification_for_wait_completion_flag (DbgEngineStackFrame *frame);
|
||||
MonoClass * get_class_to_get_builder_field(DbgEngineStackFrame *frame);
|
||||
gpointer get_this_addr (DbgEngineStackFrame *the_frame);
|
||||
|
||||
@@ -53,6 +53,8 @@ EMSCRIPTEN_KEEPALIVE gboolean mono_wasm_invoke_getter_on_object (int object_id,
|
||||
EMSCRIPTEN_KEEPALIVE gboolean mono_wasm_invoke_getter_on_value (void *value, MonoClass *klass, const char *name);
|
||||
EMSCRIPTEN_KEEPALIVE gboolean mono_wasm_get_deref_ptr_value (void *value_addr, MonoClass *klass);
|
||||
EMSCRIPTEN_KEEPALIVE void mono_wasm_set_is_debugger_attached (gboolean is_attached);
|
||||
EMSCRIPTEN_KEEPALIVE gboolean mono_wasm_set_variable_on_frame (int scope, int index, const char* name, const char* value);
|
||||
EMSCRIPTEN_KEEPALIVE gboolean mono_wasm_set_value_on_object (int object_id, const char* name, const char* value);
|
||||
|
||||
//JS functions imported that we use
|
||||
extern void mono_wasm_add_frame (int il_offset, int method_token, int frame_id, const char *assembly_name, const char *method_name);
|
||||
@@ -553,6 +555,8 @@ static void
|
||||
handle_exception (MonoException *exc, MonoContext *throw_ctx, MonoContext *catch_ctx, StackFrameInfo *catch_frame)
|
||||
{
|
||||
ERROR_DECL (error);
|
||||
const char *default_error_message = "Failed to get exception message.";
|
||||
|
||||
PRINT_DEBUG_MSG (1, "handle exception - %d - %p - %p - %p\n", pause_on_exc, exc, throw_ctx, catch_ctx);
|
||||
|
||||
//normal mono_runtime_try_invoke does not capture the exception and this is a temporary workaround.
|
||||
@@ -564,16 +568,16 @@ handle_exception (MonoException *exc, MonoContext *throw_ctx, MonoContext *catch
|
||||
return;
|
||||
|
||||
int obj_id = get_object_id ((MonoObject *)exc);
|
||||
const char *error_message = mono_string_to_utf8_checked_internal (exc->message, error);
|
||||
|
||||
if (!is_ok (error))
|
||||
error_message = "Failed to get exception message.";
|
||||
char *error_message = mono_string_to_utf8_checked_internal (exc->message, error);
|
||||
|
||||
const char *class_name = mono_class_full_name (mono_object_class (exc));
|
||||
PRINT_DEBUG_MSG (2, "handle exception - calling mono_wasm_fire_exc(): %d - message - %s, class_name: %s\n", obj_id, error_message, class_name);
|
||||
PRINT_DEBUG_MSG (2, "handle exception - calling mono_wasm_fire_exc(): %d - message - %s, class_name: %s\n", obj_id, !is_ok (error) ? error_message : default_error_message, class_name);
|
||||
|
||||
mono_wasm_fire_exception (obj_id, error_message, class_name, !catch_ctx);
|
||||
mono_wasm_fire_exception (obj_id, !is_ok (error) ? error_message : default_error_message, class_name, !catch_ctx);
|
||||
|
||||
if (error_message != NULL)
|
||||
g_free (error_message);
|
||||
|
||||
PRINT_DEBUG_MSG (2, "handle exception - done\n");
|
||||
}
|
||||
|
||||
@@ -862,6 +866,16 @@ typedef struct {
|
||||
gboolean found;
|
||||
} FrameDescData;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int cur_frame;
|
||||
int target_frame;
|
||||
int pos;
|
||||
const char* new_value;
|
||||
gboolean found;
|
||||
gboolean error;
|
||||
} SetVariableValueData;
|
||||
|
||||
/*
|
||||
* this returns a string formatted like
|
||||
*
|
||||
@@ -1514,6 +1528,194 @@ describe_variable (InterpFrame *frame, MonoMethod *method, MonoMethodHeader *hea
|
||||
return describe_value(type, addr, gpflags);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
decode_value (MonoType *t, guint8 *addr, const char* variableValue)
|
||||
{
|
||||
char* endptr;
|
||||
errno = 0;
|
||||
switch (t->type) {
|
||||
case MONO_TYPE_BOOLEAN:
|
||||
if (!strcasecmp (variableValue, "True"))
|
||||
*(guint8*)addr = 1;
|
||||
else if (!strcasecmp (variableValue, "False"))
|
||||
*(guint8*)addr = 0;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
case MONO_TYPE_CHAR:
|
||||
if (strlen (variableValue) > 1)
|
||||
return FALSE;
|
||||
*(gunichar2*)addr = variableValue [0];
|
||||
break;
|
||||
case MONO_TYPE_I1: {
|
||||
intmax_t val = strtoimax (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
if (val >= -128 && val <= 127)
|
||||
*(gint8*)addr = val;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_U1: {
|
||||
intmax_t val = strtoimax (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
if (val >= 0 && val <= 255)
|
||||
*(guint8*)addr = val;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_I2: {
|
||||
intmax_t val = strtoimax (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
if (val >= -32768 && val <= 32767)
|
||||
*(gint16*)addr = val;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_U2: {
|
||||
intmax_t val = strtoimax (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
if (val >= 0 && val <= 65535)
|
||||
*(guint16*)addr = val;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_I4: {
|
||||
intmax_t val = strtoimax (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
if (val >= -2147483648 && val <= 2147483647)
|
||||
*(gint32*)addr = val;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_U4: {
|
||||
intmax_t val = strtoimax (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
if (val >= 0 && val <= 4294967295)
|
||||
*(guint32*)addr = val;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_I8: {
|
||||
long long val = strtoll (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
*(gint64*)addr = val;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_U8: {
|
||||
long long val = strtoll (variableValue, &endptr, 10);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
*(guint64*)addr = val;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_R4: {
|
||||
gfloat val = strtof (variableValue, &endptr);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
*(gfloat*)addr = val;
|
||||
break;
|
||||
}
|
||||
case MONO_TYPE_R8: {
|
||||
gdouble val = strtof (variableValue, &endptr);
|
||||
if (errno != 0)
|
||||
return FALSE;
|
||||
*(gdouble*)addr = val;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_variable_value_on_frame (MonoStackFrameInfo *info, MonoContext *ctx, gpointer ud)
|
||||
{
|
||||
ERROR_DECL (error);
|
||||
SetVariableValueData *data = (SetVariableValueData*)ud;
|
||||
gboolean is_arg = FALSE;
|
||||
MonoType *t = NULL;
|
||||
guint8 *val_buf = NULL;
|
||||
|
||||
++data->cur_frame;
|
||||
|
||||
//skip wrappers
|
||||
if (info->type != FRAME_TYPE_MANAGED && info->type != FRAME_TYPE_INTERP) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (data->cur_frame != data->target_frame)
|
||||
return FALSE;
|
||||
|
||||
data->found = TRUE;
|
||||
|
||||
InterpFrame *frame = (InterpFrame*)info->interp_frame;
|
||||
MonoMethod *method = frame->imethod->method;
|
||||
MonoMethodSignature *sig = mono_method_signature_internal (method);
|
||||
MonoMethodHeader *header = mono_method_get_header_checked (method, error);
|
||||
|
||||
if (!header) {
|
||||
mono_error_cleanup(error);
|
||||
data->error = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!sig)
|
||||
goto exit_with_error;
|
||||
|
||||
int pos = data->pos;
|
||||
|
||||
if (pos < 0) {
|
||||
pos = - pos - 1;
|
||||
if (pos >= sig->param_count)
|
||||
goto exit_with_error;
|
||||
is_arg = TRUE;
|
||||
t = sig->params [pos];
|
||||
}
|
||||
else {
|
||||
if (pos >= header->num_locals)
|
||||
goto exit_with_error;
|
||||
t = header->locals [pos];
|
||||
}
|
||||
|
||||
guint8 *addr;
|
||||
if (is_arg)
|
||||
addr = (guint8*)mini_get_interp_callbacks ()->frame_get_arg (frame, pos);
|
||||
else
|
||||
addr = (guint8*)mini_get_interp_callbacks ()->frame_get_local (frame, pos);
|
||||
|
||||
val_buf = (guint8 *)g_alloca (mono_class_instance_size (mono_class_from_mono_type_internal (t)));
|
||||
|
||||
if (!decode_value(t, val_buf, data->new_value))
|
||||
goto exit_with_error;
|
||||
|
||||
DbgEngineErrorCode errorCode = mono_de_set_interp_var (t, addr, val_buf);
|
||||
if (errorCode != ERR_NONE) {
|
||||
goto exit_with_error;
|
||||
}
|
||||
|
||||
mono_metadata_free_mh (header);
|
||||
return TRUE;
|
||||
|
||||
exit_with_error:
|
||||
data->error = TRUE;
|
||||
mono_metadata_free_mh (header);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
describe_variables_on_frame (MonoStackFrameInfo *info, MonoContext *ctx, gpointer ud)
|
||||
{
|
||||
@@ -1553,6 +1755,24 @@ describe_variables_on_frame (MonoStackFrameInfo *info, MonoContext *ctx, gpointe
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE gboolean
|
||||
mono_wasm_set_variable_on_frame (int scope, int index, const char* name, const char* value)
|
||||
{
|
||||
if (scope < 0)
|
||||
return FALSE;
|
||||
|
||||
SetVariableValueData data;
|
||||
data.target_frame = scope;
|
||||
data.cur_frame = -1;
|
||||
data.pos = index;
|
||||
data.found = FALSE;
|
||||
data.new_value = value;
|
||||
data.error = FALSE;
|
||||
|
||||
mono_walk_stack_with_ctx (set_variable_value_on_frame, NULL, MONO_UNWIND_NONE, &data);
|
||||
return !data.error;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE gboolean
|
||||
mono_wasm_get_deref_ptr_value (void *value_addr, MonoClass *klass)
|
||||
{
|
||||
@@ -1611,6 +1831,75 @@ mono_wasm_invoke_getter_on_object (int object_id, const char* name)
|
||||
return invoke_getter (obj, mono_object_class (obj), name);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE gboolean
|
||||
mono_wasm_set_value_on_object (int object_id, const char* name, const char* value)
|
||||
{
|
||||
PRINT_DEBUG_MSG (1, "mono_wasm_set_value_on_object %d, name: %s, value: %s\n", object_id, name, value);
|
||||
MonoObject *obj = get_object_from_id (object_id);
|
||||
|
||||
if (!obj || !name) {
|
||||
PRINT_DEBUG_MSG (2, "mono_wasm_set_value_on_object: none of the arguments can be null");
|
||||
return FALSE;
|
||||
}
|
||||
MonoClass* klass = mono_object_class (obj);
|
||||
|
||||
gpointer iter;
|
||||
handle_parent:
|
||||
iter = NULL;
|
||||
MonoClassField *f;
|
||||
while ((f = mono_class_get_fields_internal (klass, &iter))) {
|
||||
if (!f->name || strcasecmp (f->name, name) != 0)
|
||||
continue;
|
||||
guint8 *val_buf = (guint8 *)g_alloca (mono_class_instance_size (mono_class_from_mono_type_internal (f->type)));
|
||||
|
||||
if (!decode_value(f->type, val_buf, value)) {
|
||||
return FALSE;
|
||||
}
|
||||
DbgEngineErrorCode errorCode = mono_de_set_interp_var (f->type, (guint8*)obj + f->offset, val_buf);
|
||||
if (errorCode != ERR_NONE) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
iter = NULL;
|
||||
MonoProperty *p;
|
||||
MonoObject *exc;
|
||||
ERROR_DECL (error);
|
||||
while ((p = mono_class_get_properties (klass, &iter))) {
|
||||
if (!p->name || strcasecmp (p->name, name) != 0)
|
||||
continue;
|
||||
if (!p->set)
|
||||
break;
|
||||
MonoType *type = mono_method_signature_internal (p->set)->params [0];
|
||||
guint8 *val_buf = (guint8 *)g_alloca (mono_class_instance_size (mono_class_from_mono_type_internal (type)));
|
||||
|
||||
if (!decode_value(type, val_buf, value)) {
|
||||
return FALSE;
|
||||
}
|
||||
mono_runtime_try_invoke (p->set, obj, (void **)&val_buf, &exc, error);
|
||||
if (!is_ok (error) && exc == NULL)
|
||||
exc = (MonoObject*) mono_error_convert_to_exception (error);
|
||||
if (exc) {
|
||||
char *error_message = mono_string_to_utf8_checked_internal (((MonoException *)exc)->message, error);
|
||||
if (is_ok (error)) {
|
||||
PRINT_DEBUG_MSG (2, "mono_wasm_set_value_on_object exception: %s\n", error_message);
|
||||
g_free (error_message);
|
||||
mono_error_cleanup (error);
|
||||
}
|
||||
else {
|
||||
PRINT_DEBUG_MSG (2, "mono_wasm_set_value_on_object exception\n");
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ((klass = m_class_get_parent(klass)))
|
||||
goto handle_parent;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE gboolean
|
||||
mono_wasm_invoke_getter_on_value (void *value, MonoClass *klass, const char *name)
|
||||
{
|
||||
|
||||
@@ -192,6 +192,11 @@ namespace Microsoft.WebAssembly.Diagnostics
|
||||
return new MonoCommands($"MONO.mono_wasm_get_variables({scopeId}, {JsonConvert.SerializeObject(var_ids)})");
|
||||
}
|
||||
|
||||
public static MonoCommands SetVariableValue(int scopeId, int index, string name, string newValue)
|
||||
{
|
||||
return new MonoCommands($"MONO.mono_wasm_set_variable_value({scopeId}, {index}, '{name}', '{newValue}')");
|
||||
}
|
||||
|
||||
public static MonoCommands EvaluateMemberAccess(int scopeId, string expr, params VarInfo[] vars)
|
||||
{
|
||||
var var_ids = vars.Select(v => new { index = v.Index, name = v.Name }).ToArray();
|
||||
|
||||
@@ -322,6 +322,22 @@ namespace Microsoft.WebAssembly.Diagnostics
|
||||
{
|
||||
return await Step(id, StepKind.Into, token);
|
||||
}
|
||||
case "Debugger.setVariableValue":
|
||||
{
|
||||
if (!DotnetObjectId.TryParse(args?["callFrameId"], out DotnetObjectId objectId))
|
||||
return false;
|
||||
switch (objectId.Scheme)
|
||||
{
|
||||
case "scope":
|
||||
return await OnSetVariableValue(id,
|
||||
int.Parse(objectId.Value),
|
||||
args?["variableName"]?.Value<string>(),
|
||||
args?["newValue"],
|
||||
token);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
case "Debugger.stepOut":
|
||||
{
|
||||
@@ -470,6 +486,26 @@ namespace Microsoft.WebAssembly.Diagnostics
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<bool> OnSetVariableValue(MessageId id, int scopeId, string varName, JToken varValue, CancellationToken token)
|
||||
{
|
||||
ExecutionContext ctx = GetContext(id);
|
||||
Frame scope = ctx.CallStack.FirstOrDefault(s => s.Id == scopeId);
|
||||
if (scope == null)
|
||||
return false;
|
||||
var varIds = scope.Method.GetLiveVarsAt(scope.Location.CliLocation.Offset);
|
||||
if (varIds == null)
|
||||
return false;
|
||||
var varToSetValue = varIds.FirstOrDefault(v => v.Name == varName);
|
||||
if (varToSetValue == null)
|
||||
return false;
|
||||
Result res = await SendMonoCommand(id, MonoCommands.SetVariableValue(scopeId, varToSetValue.Index, varName, varValue["value"].Value<string>()), token);
|
||||
if (res.IsOk)
|
||||
SendResponse(id, Result.Ok(new JObject()), token);
|
||||
else
|
||||
SendResponse(id, Result.Err($"Unable to set '{varValue["value"].Value<string>()}' to variable '{varName}'"), token);
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<Result> RuntimeGetProperties(MessageId id, DotnetObjectId objectId, JToken args, CancellationToken token)
|
||||
{
|
||||
if (objectId.Scheme == "scope")
|
||||
|
||||
@@ -231,6 +231,20 @@ namespace DebuggerTests
|
||||
Assert.True(false, $"Could not find variable '{name}'");
|
||||
}
|
||||
|
||||
internal void CheckNumberAsString(JToken locals, string name, string value)
|
||||
{
|
||||
foreach (var l in locals)
|
||||
{
|
||||
if (name != l["name"]?.Value<string>())
|
||||
continue;
|
||||
var val = l["value"];
|
||||
Assert.Equal("number", val["type"]?.Value<string>());
|
||||
Assert.Equal(value, val["value"].ToString());
|
||||
return;
|
||||
}
|
||||
Assert.True(false, $"Could not find variable '{name}'");
|
||||
}
|
||||
|
||||
internal void CheckString(JToken locals, string name, string value)
|
||||
{
|
||||
var l = GetAndAssertObjectWithName(locals, name);
|
||||
@@ -389,6 +403,21 @@ namespace DebuggerTests
|
||||
return res;
|
||||
}
|
||||
|
||||
internal async Task<Result> SetValueOnObject(JToken obj, string property, string newvalue, string fn = "function(a, b) { this[a] = b; }", bool expect_ok = true)
|
||||
{
|
||||
var req = JObject.FromObject(new
|
||||
{
|
||||
functionDeclaration = fn,
|
||||
objectId = obj["value"]?["objectId"]?.Value<string>(),
|
||||
arguments = new[] { new { value = property } , new { value = newvalue } },
|
||||
silent = true
|
||||
});
|
||||
var res = await cli.SendCommand("Runtime.callFunctionOn", req, token);
|
||||
Assert.True(expect_ok == res.IsOk, $"SetValueOnObject failed for {req} with {res}");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
internal async Task<JObject> StepAndCheck(StepKind kind, string script_loc, int line, int column, string function_name,
|
||||
Func<JObject, Task> wait_for_event_fn = null, Action<JToken> locals_fn = null, int times = 1)
|
||||
{
|
||||
@@ -789,6 +818,16 @@ namespace DebuggerTests
|
||||
return (null, res);
|
||||
}
|
||||
|
||||
internal async Task<(JToken, Result)> SetVariableValueOnCallFrame(JObject parms, bool expect_ok = true)
|
||||
{
|
||||
var res = await cli.SendCommand("Debugger.setVariableValue", parms, token);
|
||||
AssertEqual(expect_ok, res.IsOk, $"Debugger.setVariableValue ('{parms}') returned {res.IsOk} instead of {expect_ok}, with Result: {res}");
|
||||
if (res.IsOk)
|
||||
return (res.Value["result"], res);
|
||||
|
||||
return (null, res);
|
||||
}
|
||||
|
||||
internal async Task<Result> RemoveBreakpoint(string id, bool expect_ok = true)
|
||||
{
|
||||
var remove_bp = JObject.FromObject(new
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.WebAssembly.Diagnostics;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace DebuggerTests
|
||||
{
|
||||
public class SetVariableValueTests : DebuggerTestBase
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("a", 1, 30, 130)]
|
||||
[InlineData("a", 1, -30, -130)]
|
||||
[InlineData("a1", 1, 20, -1)]
|
||||
[InlineData("a1", 1, 20, 256)]
|
||||
[InlineData("b", 2, 200, -32769)]
|
||||
[InlineData("b", 2, -500, 32769)]
|
||||
[InlineData("b2", 3, 30000, -500)]
|
||||
[InlineData("b2", 3, 30000, 65550)]
|
||||
[InlineData("d", 5, 70, -2147483649)]
|
||||
[InlineData("d", 5, 70, 2147483648)]
|
||||
[InlineData("d2", 6, 70, -50)]
|
||||
[InlineData("d2", 6, 70, 4294967296)]
|
||||
public async Task SetLocalPrimitiveTypeVariableOutOfRange(string variableName, long originalValue, long newValue, long overflowValue) {
|
||||
await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.SetVariableLocals", "run", 12);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTests.SetVariableLocals:run');}}, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 22, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 23, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue);
|
||||
}
|
||||
);
|
||||
|
||||
callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=overflowValue}) }), false);
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 24, 8, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("f", 9, 150.15616, 0.4564)]
|
||||
[InlineData("f", 9, -454.54654, -0.5648)]
|
||||
public async Task SetLocalFloatVariable(string variableName, float originalValue, float newValue, float newValue2) {
|
||||
await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.SetVariableLocals", "run", 12);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTests.SetVariableLocals:run');}}, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 22, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 23, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue);
|
||||
}
|
||||
);
|
||||
|
||||
callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue2}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 24, 8, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue2);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("g", 10, 150.15615844726562, 0.4564000070095062)]
|
||||
[InlineData("g", 10, -454.5465393066406, -0.5648000240325928)]
|
||||
public async Task SetLocalDoubleVariable(string variableName, double originalValue, double newValue, double newValue2) {
|
||||
await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.SetVariableLocals", "run", 12);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTests.SetVariableLocals:run');}}, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 22, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 23, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue);
|
||||
}
|
||||
);
|
||||
|
||||
callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue2}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 24, 8, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue2);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("a", "1", "30", "127")]
|
||||
[InlineData("a", "1", "-30", "-128")]
|
||||
[InlineData("a1", "1", "20", "0")]
|
||||
[InlineData("a1", "1", "20", "255")]
|
||||
[InlineData("b", "2", "200", "-32768")]
|
||||
[InlineData("b", "2", "-500", "32767")]
|
||||
[InlineData("b2", "3", "30000", "65535")]
|
||||
[InlineData("d", "5", "70", "-2147483648")]
|
||||
[InlineData("d", "5", "70", "2147483647")]
|
||||
[InlineData("d2", "6", "70", "4294967295")]
|
||||
[InlineData("e", "7", "70", "-9223372036854775808")]
|
||||
[InlineData("e", "7", "70", "9254456")]
|
||||
[InlineData("e2", "8", "70", "184467")]
|
||||
public async Task SetLocalPrimitiveTypeVariableValid(string variableName, string originalValue, string newValue, string newValue2) {
|
||||
await SetBreakpointInMethod("debugger-test.dll", "DebuggerTests.SetVariableLocals", "run", 12);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() {{ invoke_static_method_async('[debugger-test] DebuggerTests.SetVariableLocals:run');}}, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 22, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumberAsString(locals, variableName, originalValue.ToString());
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 23, 12, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumberAsString(locals, variableName, newValue.ToString());
|
||||
}
|
||||
);
|
||||
|
||||
callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue2}) }));
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-set-variable-value-test.cs", 24, 8, "run",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumberAsString(locals, variableName, newValue2.ToString());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, "a", 10, 30)]
|
||||
[InlineData(1, "a", 10, -1)]
|
||||
[InlineData(1, "b", 20, 30)]
|
||||
[InlineData(2, "c", 30, 60)]
|
||||
[InlineData(3, "d", 50, 70)]
|
||||
public async Task SetLocalPrimitiveTypeVariable(int offset, string variableName, int originalValue, int newValue){
|
||||
await SetBreakpointInMethod("debugger-test.dll", "Math", "IntAdd", offset);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() { invoke_add(); }, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-test.cs", 8+offset, 8, "IntAdd",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue}) }));
|
||||
|
||||
await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 9+offset, 8, "IntAdd",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, newValue);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, "a", 10, "wrongValue")]
|
||||
[InlineData(1, "b", 20, "wrongValue")]
|
||||
[InlineData(2, "c", 30, "wrongValue")]
|
||||
[InlineData(3, "d", 50, "wrongValue")]
|
||||
public async Task SetVariableValuesAtBreakpointSiteFail(int offset, string variableName, int originalValue, string invalidValue){
|
||||
await SetBreakpointInMethod("debugger-test.dll", "Math", "IntAdd", offset);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() { invoke_add(); }, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-test.cs", 8+offset, 8, "IntAdd",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=invalidValue}) }), false);
|
||||
|
||||
await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 9+offset, 8, "IntAdd",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckNumber(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5, "f", true, false)]
|
||||
[InlineData(5, "f", true, true)]
|
||||
public async Task SetLocalBoolTypeVariable(int offset, string variableName, bool originalValue, bool newValue){
|
||||
await SetBreakpointInMethod("debugger-test.dll", "Math", "IntAdd", offset);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() { invoke_add(); }, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-test.cs", 8+offset, 8, "IntAdd",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckBool(locals, variableName, originalValue);
|
||||
}
|
||||
);
|
||||
var callFrameId = pause_location["callFrames"][0]["callFrameId"].Value<string>();
|
||||
|
||||
await SetVariableValueOnCallFrame( JObject.FromObject(new {callFrameId, variableName, newValue=JObject.FromObject(new {value=newValue}) }));
|
||||
|
||||
await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 9+offset, 4, "IntAdd",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
CheckBool(locals, variableName, newValue);
|
||||
}
|
||||
);
|
||||
}
|
||||
[Theory]
|
||||
[InlineData("A", 10, "20", true)]
|
||||
[InlineData("A", 10, "error", false)]
|
||||
[InlineData("d", 15, "20", true)]
|
||||
[InlineData("d", 15, "error", false)]
|
||||
public async Task TestSetValueOnObject(string prop_name, int prop_value, string prop_new_value, bool expect_ok)
|
||||
{
|
||||
var bp = await SetBreakpointInMethod("debugger-test.dll", "Math", "UseComplex", 5);
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() { invoke_use_complex(); }, 1);",
|
||||
"dotnet://debugger-test.dll/debugger-test.cs",
|
||||
bp.Value["locations"][0]["lineNumber"].Value<int>(),
|
||||
bp.Value["locations"][0]["columnNumber"].Value<int>(),
|
||||
"UseComplex");
|
||||
|
||||
|
||||
var frame = pause_location["callFrames"][0];
|
||||
var props = await GetObjectOnFrame(frame, "complex");
|
||||
var locals = await GetProperties(frame["callFrameId"].Value<string>());
|
||||
var obj = GetAndAssertObjectWithName(locals, "complex");
|
||||
Assert.Equal(4, props.Count());
|
||||
CheckNumber(props, prop_name, prop_value);
|
||||
CheckString(props, "B", "xx");
|
||||
|
||||
await SetValueOnObject(obj, prop_name, prop_new_value, expect_ok: expect_ok);
|
||||
|
||||
pause_location = await StepAndCheck(
|
||||
StepKind.Over,
|
||||
"dotnet://debugger-test.dll/debugger-test.cs",
|
||||
bp.Value["locations"][0]["lineNumber"].Value<int>()+1,
|
||||
bp.Value["locations"][0]["columnNumber"].Value<int>(),
|
||||
"UseComplex");
|
||||
|
||||
frame = pause_location["callFrames"][0];
|
||||
props = await GetObjectOnFrame(frame, "complex");
|
||||
locals = await GetProperties(frame["callFrameId"].Value<string>());
|
||||
Assert.Equal(4, props.Count());
|
||||
CheckNumber(props, prop_name, expect_ok ? Int32.Parse(prop_new_value) : prop_value);
|
||||
CheckString(props, "B", "xx");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -92,14 +92,14 @@ namespace DebuggerTests
|
||||
UseCallFunctionOnBeforeGetProperties = use_cfo;
|
||||
|
||||
var dep_cs_loc = "dotnet://debugger-test.dll/dependency.cs";
|
||||
await SetBreakpoint(dep_cs_loc, 33, 8);
|
||||
await SetBreakpoint(dep_cs_loc, 35, 8);
|
||||
|
||||
var debugger_test_loc = "dotnet://debugger-test.dll/debugger-test.cs";
|
||||
|
||||
// Will stop in Complex.DoEvenMoreStuff
|
||||
var pause_location = await EvaluateAndCheck(
|
||||
"window.setTimeout(function() { invoke_use_complex (); }, 1);",
|
||||
dep_cs_loc, 33, 8, "DoEvenMoreStuff",
|
||||
dep_cs_loc, 35, 8, "DoEvenMoreStuff",
|
||||
locals_fn: (locals) =>
|
||||
{
|
||||
Assert.Single(locals);
|
||||
@@ -108,7 +108,7 @@ namespace DebuggerTests
|
||||
);
|
||||
|
||||
var props = await GetObjectOnFrame(pause_location["callFrames"][0], "this");
|
||||
Assert.Equal(3, props.Count());
|
||||
Assert.Equal(4, props.Count());
|
||||
CheckNumber(props, "A", 10);
|
||||
CheckString(props, "B", "xx");
|
||||
CheckString(props, "c", "20_xx");
|
||||
@@ -126,12 +126,12 @@ namespace DebuggerTests
|
||||
CheckNumber(locals_m1, "f", 0);
|
||||
|
||||
props = await GetObjectOnFrame(pause_location["callFrames"][3], "complex");
|
||||
Assert.Equal(3, props.Count());
|
||||
Assert.Equal(4, props.Count());
|
||||
CheckNumber(props, "A", 10);
|
||||
CheckString(props, "B", "xx");
|
||||
CheckString(props, "c", "20_xx");
|
||||
|
||||
pause_location = await StepAndCheck(StepKind.Over, dep_cs_loc, 23, 8, "DoStuff", times: 2);
|
||||
pause_location = await StepAndCheck(StepKind.Over, dep_cs_loc, 25, 8, "DoStuff", times: 2);
|
||||
// Check UseComplex frame again
|
||||
locals_m1 = await GetLocalsForFrame(pause_location["callFrames"][1], debugger_test_loc, 23, 8, "UseComplex");
|
||||
Assert.Equal(7, locals_m1.Count());
|
||||
@@ -145,7 +145,7 @@ namespace DebuggerTests
|
||||
CheckNumber(locals_m1, "f", 0);
|
||||
|
||||
props = await GetObjectOnFrame(pause_location["callFrames"][1], "complex");
|
||||
Assert.Equal(3, props.Count());
|
||||
Assert.Equal(4, props.Count());
|
||||
CheckNumber(props, "A", 10);
|
||||
CheckString(props, "B", "xx");
|
||||
CheckString(props, "c", "20_xx");
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
namespace DebuggerTests
|
||||
{
|
||||
public class SetVariableLocals
|
||||
{
|
||||
public static void run()
|
||||
{
|
||||
sbyte a = 1;
|
||||
byte a1 = 1;
|
||||
short b = 2;
|
||||
ushort b2 = 3;
|
||||
int d = 5;
|
||||
uint d2 = 6;
|
||||
long e = 7;
|
||||
ulong e2 = 8;
|
||||
float f = 9;
|
||||
double g = 10;
|
||||
System.Console.WriteLine(g);
|
||||
System.Console.WriteLine(f);
|
||||
System.Console.WriteLine(e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public partial class Math
|
||||
int c = a + b;
|
||||
int d = c + b;
|
||||
int e = d + a;
|
||||
int f = 0;
|
||||
bool f = true;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ namespace Simple
|
||||
public int A { get; set; }
|
||||
public string B { get; set; }
|
||||
object c;
|
||||
public int d;
|
||||
|
||||
public Complex(int a, string b)
|
||||
{
|
||||
A = a;
|
||||
B = b;
|
||||
this.c = this;
|
||||
d = 15;
|
||||
}
|
||||
|
||||
public int DoStuff()
|
||||
|
||||
@@ -759,6 +759,14 @@ var MonoSupportLib = {
|
||||
throw new Error(`Could not get a value for ${root}`);
|
||||
|
||||
return this._resolve_member_by_name(rootObject, root, parts);
|
||||
},
|
||||
|
||||
mono_wasm_set_variable_value: function (scope, index, name, newValue) {
|
||||
console.debug (">> mono_wasm_set_variable_value " + name + " - " + newValue);
|
||||
var ret = this._c_fn_table.mono_wasm_set_variable_on_frame_wrapper(scope, index, name, newValue);
|
||||
if (ret == false)
|
||||
throw new Error(`Could not get a value for ${name}`);
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1224,6 +1232,32 @@ var MonoSupportLib = {
|
||||
return getter_res.length > 0 ? getter_res [0] : {};
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} objectIdStr objectId
|
||||
* @param {string} name property name
|
||||
* @returns {object} return true if it works and false if it doesn't
|
||||
*/
|
||||
_set_value_on_object: function (objectIdStr, name, newvalue) {
|
||||
const id = this._parse_object_id (objectIdStr);
|
||||
if (id === undefined)
|
||||
throw new Error (`Invalid object id: ${objectIdStr}`);
|
||||
|
||||
let setter_res;
|
||||
if (id.scheme == 'object') {
|
||||
if (isNaN (id.o) || id.o < 0)
|
||||
throw new Error (`Invalid object id: ${objectIdStr}`);
|
||||
|
||||
var ret = this._c_fn_table.mono_wasm_set_value_on_object_wrapper (id.o, name, newvalue);
|
||||
if (!ret)
|
||||
throw new Error (`Invoking setter on ${objectIdStr} failed`);
|
||||
|
||||
setter_res = ret;
|
||||
}
|
||||
else
|
||||
throw new Error (`Only object is supported for setters, id: ${objectIdStr}`);
|
||||
return setter_res;
|
||||
},
|
||||
|
||||
_create_proxy_from_object_id: function (objectId) {
|
||||
const details = this.mono_wasm_get_details(objectId);
|
||||
|
||||
@@ -1245,7 +1279,10 @@ var MonoSupportLib = {
|
||||
}
|
||||
});
|
||||
|
||||
return proxy;
|
||||
const handler1 = {
|
||||
set (obj, prop, newValue) {return MONO._set_value_on_object (objectId, prop, newValue.toString());},
|
||||
};
|
||||
return new Proxy(proxy, handler1);
|
||||
},
|
||||
|
||||
mono_wasm_call_function_on: function (request) {
|
||||
@@ -1384,12 +1421,14 @@ var MonoSupportLib = {
|
||||
this._call_function_res_cache = {};
|
||||
|
||||
this._c_fn_table = {};
|
||||
this._register_c_var_fn ('mono_wasm_get_object_properties', 'bool', [ 'number', 'number' ]);
|
||||
this._register_c_var_fn ('mono_wasm_get_array_values', 'bool', [ 'number', 'number', 'number', 'number' ]);
|
||||
this._register_c_var_fn ('mono_wasm_invoke_getter_on_object', 'bool', [ 'number', 'string' ]);
|
||||
this._register_c_var_fn ('mono_wasm_invoke_getter_on_value', 'bool', [ 'number', 'number', 'string' ]);
|
||||
this._register_c_var_fn ('mono_wasm_get_local_vars', 'bool', [ 'number', 'number', 'number']);
|
||||
this._register_c_var_fn ('mono_wasm_get_deref_ptr_value', 'bool', [ 'number', 'number']);
|
||||
this._register_c_var_fn ('mono_wasm_get_object_properties', 'bool', [ 'number', 'number' ]);
|
||||
this._register_c_var_fn ('mono_wasm_get_array_values', 'bool', [ 'number', 'number', 'number', 'number' ]);
|
||||
this._register_c_var_fn ('mono_wasm_invoke_getter_on_object', 'bool', [ 'number', 'string' ]);
|
||||
this._register_c_var_fn ('mono_wasm_invoke_getter_on_value', 'bool', [ 'number', 'number', 'string' ]);
|
||||
this._register_c_var_fn ('mono_wasm_get_local_vars', 'bool', [ 'number', 'number', 'number']);
|
||||
this._register_c_var_fn ('mono_wasm_get_deref_ptr_value', 'bool', [ 'number', 'number']);
|
||||
this._register_c_fn ('mono_wasm_set_value_on_object', 'bool', [ 'number', 'string', 'string' ]);
|
||||
this._register_c_fn ('mono_wasm_set_variable_on_frame', 'bool', [ 'number', 'number', 'string', 'string']);
|
||||
// DO NOT REMOVE - magic debugger init function
|
||||
if (globalThis.dotnetDebugger)
|
||||
debugger;
|
||||
@@ -1904,7 +1943,7 @@ var MonoSupportLib = {
|
||||
|
||||
if (invariantMode)
|
||||
this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1");
|
||||
|
||||
|
||||
// Set globalization mode to PredefinedCulturesOnly
|
||||
this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", "1");
|
||||
},
|
||||
@@ -2099,7 +2138,8 @@ var MonoSupportLib = {
|
||||
type: "boolean",
|
||||
value: v,
|
||||
description: v.toString ()
|
||||
}
|
||||
},
|
||||
writable:true
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -2111,7 +2151,8 @@ var MonoSupportLib = {
|
||||
type: "symbol",
|
||||
value: v,
|
||||
description: v
|
||||
}
|
||||
},
|
||||
writable:true
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -2122,7 +2163,8 @@ var MonoSupportLib = {
|
||||
type: "number",
|
||||
value: value,
|
||||
description: '' + value
|
||||
}
|
||||
},
|
||||
writable:true
|
||||
});
|
||||
break;
|
||||
|
||||
|
||||
Reference in new issue
Block a user