Skip to content

Commit ac17c08

Browse files
author
David Karlaš
committed
Bug 44266 - Unable to change variable values whilst debugging
1 parent f673203 commit ac17c08

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public abstract class Connection
421421
* with newer runtimes, and vice versa.
422422
*/
423423
internal const int MAJOR_VERSION = 2;
424-
internal const int MINOR_VERSION = 43;
424+
internal const int MINOR_VERSION = 44;
425425

426426
enum WPSuspendPolicy {
427427
NONE = 0,
@@ -591,6 +591,7 @@ enum CmdStackFrame {
591591
GET_THIS = 2,
592592
SET_VALUES = 3,
593593
GET_DOMAIN = 4,
594+
SET_THIS = 5,
594595
}
595596

596597
enum CmdArrayRef {
@@ -2400,6 +2401,10 @@ internal long StackFrame_GetDomain (long thread_id, long id) {
24002401
return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
24012402
}
24022403

2404+
internal void StackFrame_SetThis (long thread_id, long id, ValueImpl value) {
2405+
SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteValue (value));
2406+
}
2407+
24032408
/*
24042409
* ARRAYS
24052410
*/

Mono.Debugger.Soft/Mono.Debugger.Soft/StackFrame.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ public Value GetThis () {
178178
return vm.DecodeValue (vm.conn.StackFrame_GetThis (thread.Id, Id));
179179
}
180180

181+
// Since protocol version 2.44
182+
public void SetThis (Value value) {
183+
if (value == null)
184+
throw new ArgumentNullException ("value");
185+
if (Method.IsStatic || !Method.DeclaringType.IsValueType)
186+
throw new InvalidOperationException ("The frame's method needs to be a valuetype instance method.");
187+
vm.conn.StackFrame_SetThis (thread.Id, Id, vm.EncodeValue (value));
188+
}
189+
181190
public void SetValue (LocalVariable var, Value value) {
182191
if (var == null)
183192
throw new ArgumentNullException ("var");

Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ internal Value[] DecodeValues (ValueImpl[] values, Dictionary<int, Value> parent
665665
return res;
666666
}
667667

668-
internal ValueImpl EncodeValue (Value v) {
668+
internal ValueImpl EncodeValue (Value v, List<Value> duplicates = null) {
669669
if (v is PrimitiveValue) {
670670
object val = (v as PrimitiveValue).Value;
671671
if (val == null)
@@ -675,16 +675,22 @@ internal ValueImpl EncodeValue (Value v) {
675675
} else if (v is ObjectMirror) {
676676
return new ValueImpl { Type = ElementType.Object, Objid = (v as ObjectMirror).Id };
677677
} else if (v is StructMirror) {
678-
return new ValueImpl { Type = ElementType.ValueType, Klass = (v as StructMirror).Type.Id, Fields = EncodeValues ((v as StructMirror).Fields) };
678+
if (duplicates == null)
679+
duplicates = new List<Value> ();
680+
if (duplicates.Contains (v))
681+
return new ValueImpl { Type = (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL, Objid = 0 };
682+
duplicates.Add (v);
683+
684+
return new ValueImpl { Type = ElementType.ValueType, Klass = (v as StructMirror).Type.Id, Fields = EncodeValues ((v as StructMirror).Fields, duplicates) };
679685
} else {
680686
throw new NotSupportedException ();
681687
}
682688
}
683689

684-
internal ValueImpl[] EncodeValues (IList<Value> values) {
690+
internal ValueImpl[] EncodeValues (IList<Value> values, List<Value> duplicates = null) {
685691
ValueImpl[] res = new ValueImpl [values.Count];
686692
for (int i = 0; i < values.Count; ++i)
687-
res [i] = EncodeValue (values [i]);
693+
res [i] = EncodeValue (values [i], duplicates);
688694
return res;
689695
}
690696

Mono.Debugging.Soft/SoftDebuggerAdaptor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,14 @@ IEnumerable<ValueReference> GetHoistedLocalVariables (SoftEvaluationContext cx,
774774
var name = GetHoistedIteratorLocalName (field, cx);
775775

776776
if (!string.IsNullOrEmpty (name))
777-
list.Add (new FieldValueReference (cx, field, val, type, name, ObjectValueFlags.Variable));
777+
list.Add (new FieldValueReference (cx, field, val, type, name, ObjectValueFlags.Variable) {
778+
ParentSource = vthis
779+
});
778780
}
779781
} else if (!field.Name.Contains ("$")) {
780-
list.Add (new FieldValueReference (cx, field, val, type, field.Name, ObjectValueFlags.Variable));
782+
list.Add (new FieldValueReference (cx, field, val, type, field.Name, ObjectValueFlags.Variable) {
783+
ParentSource = vthis
784+
});
781785
}
782786
}
783787

Mono.Debugging.Soft/ThisValueReference.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public override object Value {
6060
return value;
6161
}
6262
set {
63-
throw new NotSupportedException ();
63+
if (frame.VirtualMachine.Version.AtLeast (2, 44)) {
64+
this.value = (Value)value;
65+
frame.SetThis ((Value)value);
66+
}
6467
}
6568
}
6669

Mono.Debugging/Mono.Debugging.Evaluation/ValueReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public virtual IEnumerable<ValueReference> GetChildReferences (EvaluationOptions
243243
return new ValueReference [0];
244244
}
245245

246-
public IObjectSource ParentSource { get; internal set; }
246+
public IObjectSource ParentSource { get; set; }
247247

248248
protected EvaluationContext GetChildrenContext (EvaluationOptions options)
249249
{

0 commit comments

Comments
 (0)