2 using System.Collections.Generic;
5 namespace Mono.Debugger.Soft
7 public class StackFrame : Mirror
13 StackFrameFlags flags;
16 * FIXME: Decide on the way to request/handle debugging information:
17 * - request the info in bulk for all frames/on demand for individual frames
18 * - request the info from the runtime/request only the il offset, and compute
19 * everything else based on this info using the method debug info.
22 internal StackFrame (VirtualMachine vm, long id, ThreadMirror thread, MethodMirror method, int il_offset, StackFrameFlags flags) : base (vm, id) {
25 this.il_offset = il_offset;
29 public ThreadMirror Thread {
35 public MethodMirror Method {
41 public Location Location {
43 if (location == null) {
45 string src_file = null;
47 int column_number = 0;
48 int end_line_number = -1;
49 int end_column_number = -1;
54 line_number = method.il_offset_to_line_number (il_offset, out src_file, out hash, out column_number, out end_line_number, out end_column_number);
56 location = new Location (vm, Method, 0, il_offset, src_file != null ? src_file : method.SourceFile, line_number, column_number, end_line_number, end_column_number, hash);
62 public string FileName {
64 return Location.SourceFile;
70 return Location.ILOffset;
74 public int LineNumber {
76 return Location.LineNumber;
80 public int ColumnNumber {
82 return Location.ColumnNumber;
86 public bool IsDebuggerInvoke {
88 return (flags & StackFrameFlags.DEBUGGER_INVOKE) != 0;
93 * Whenever this frame transitions to native code. The method associated
94 * with the frame is either an InternalCall or a pinvoke method.
96 public bool IsNativeTransition {
98 return (flags & StackFrameFlags.NATIVE_TRANSITION) != 0;
102 public Value GetValue (ParameterInfoMirror param) {
104 throw new ArgumentNullException ("param");
105 if (param.Method != Method)
106 throw new ArgumentException ("Parameter doesn't belong to this frame's method.");
108 throw new ArgumentException ("Parameter represents the method return value.");
111 // FIXME: Allow returning the frame return value if possible
112 return vm.DecodeValue (vm.conn.StackFrame_GetValues (thread.Id, Id, new int [] { (- param.Position) - 1 })[0]);
115 public Value GetValue (LocalVariable var) {
117 throw new ArgumentNullException ("var");
118 if (var.Method != Method)
119 throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
122 // FIXME: Check for return value
123 // FIXME: Allow returning the frame return value if possible
124 return vm.DecodeValue (vm.conn.StackFrame_GetValues (thread.Id, Id, new int [] { var.GetValueIndex } )[0]);
127 public Value[] GetValues (LocalVariable[] vars) {
129 throw new ArgumentNullException ("vars");
130 for (int i = 0; i < vars.Length; ++i) {
131 if (vars [i] == null)
132 throw new ArgumentNullException ("vars");
133 if (vars [i].Method != Method)
134 throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
136 int[] pos = new int [vars.Length];
137 for (int i = 0; i < vars.Length; ++i)
138 pos [i] = vars [i].GetValueIndex;
139 return vm.DecodeValues (vm.conn.StackFrame_GetValues (thread.Id, Id, pos));
142 public Value GetArgument (int pos) {
143 return GetValue (Method.GetParameters () [pos]);
146 public Value GetThis () {
147 return vm.DecodeValue (vm.conn.StackFrame_GetThis (thread.Id, Id));
150 public void SetValue (LocalVariable var, Value value) {
152 throw new ArgumentNullException ("var");
153 if (var.Method != Method)
154 throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
156 throw new ArgumentNullException ("value");
159 // FIXME: Check for return value
161 vm.conn.StackFrame_SetValues (thread.Id, Id, new int [] { var.GetValueIndex }, new ValueImpl [] { vm.EncodeValue (value) });
162 } catch (CommandException ex) {
163 if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
164 throw new ArgumentException ("Value does not match the type of the local variable.");
170 public void SetValue (ParameterInfoMirror param, Value value) {
172 throw new ArgumentNullException ("param");
173 if (param.Method != Method)
174 throw new ArgumentException ("Parameter doesn't belong to this frame's method.");
176 throw new ArgumentException ("Parameter represents the method return value.");
178 throw new ArgumentNullException ("value");
182 // FIXME: Allow setting the frame return value if possible
184 vm.conn.StackFrame_SetValues (thread.Id, Id, new int [] { (- param.Position) - 1 }, new ValueImpl [] { vm.EncodeValue (value) });
185 } catch (CommandException ex) {
186 if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
187 throw new ArgumentException ("Value does not match the type of the variable.");
193 public IList<LocalVariable> GetVisibleVariables () {
194 if (Location.ILOffset == -1)
195 throw new AbsentInformationException ();
197 return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset).ToList ();
200 public LocalVariable GetVisibleVariableByName (string name) {
202 throw new ArgumentNullException ("name");
204 if (Location.ILOffset == -1)
205 throw new AbsentInformationException ();
207 return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset && l.Name == name).FirstOrDefault ();