2 using System.Collections.Generic;
5 namespace Mono.Debugger.Soft
7 public class StackFrame : Mirror
10 AppDomainMirror domain;
14 StackFrameFlags flags;
17 * FIXME: Decide on the way to request/handle debugging information:
18 * - request the info in bulk for all frames/on demand for individual frames
19 * - request the info from the runtime/request only the il offset, and compute
20 * everything else based on this info using the method debug info.
23 internal StackFrame (VirtualMachine vm, long id, ThreadMirror thread, MethodMirror method, int il_offset, StackFrameFlags flags) : base (vm, id) {
26 this.il_offset = il_offset;
30 public ThreadMirror Thread {
36 public AppDomainMirror Domain {
38 vm.CheckProtocolVersion (2, 38);
40 domain = vm.GetDomain (vm.conn.StackFrame_GetDomain (thread.Id, Id));
46 public MethodMirror Method {
52 public Location Location {
54 if (location == null) {
56 string src_file = null;
58 int column_number = 0;
59 int end_line_number = -1;
60 int end_column_number = -1;
65 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);
67 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);
73 public string FileName {
75 return Location.SourceFile;
81 return Location.ILOffset;
85 public int LineNumber {
87 return Location.LineNumber;
91 public int ColumnNumber {
93 return Location.ColumnNumber;
97 public bool IsDebuggerInvoke {
99 return (flags & StackFrameFlags.DEBUGGER_INVOKE) != 0;
104 * Whenever this frame transitions to native code. The method associated
105 * with the frame is either an InternalCall or a pinvoke method.
107 public bool IsNativeTransition {
109 return (flags & StackFrameFlags.NATIVE_TRANSITION) != 0;
113 public Value GetValue (ParameterInfoMirror param) {
115 throw new ArgumentNullException ("param");
116 if (param.Method != Method)
117 throw new ArgumentException ("Parameter doesn't belong to this frame's method.");
119 throw new ArgumentException ("Parameter represents the method return value.");
122 // FIXME: Allow returning the frame return value if possible
123 return vm.DecodeValue (vm.conn.StackFrame_GetValues (thread.Id, Id, new int [] { (- param.Position) - 1 })[0]);
126 public Value GetValue (LocalVariable var) {
128 throw new ArgumentNullException ("var");
129 if (var.Method != Method)
130 throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
133 // FIXME: Check for return value
134 // FIXME: Allow returning the frame return value if possible
135 return vm.DecodeValue (vm.conn.StackFrame_GetValues (thread.Id, Id, new int [] { var.GetValueIndex } )[0]);
138 public Value[] GetValues (LocalVariable[] vars) {
140 throw new ArgumentNullException ("vars");
141 for (int i = 0; i < vars.Length; ++i) {
142 if (vars [i] == null)
143 throw new ArgumentNullException ("vars");
144 if (vars [i].Method != Method)
145 throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
147 int[] pos = new int [vars.Length];
148 for (int i = 0; i < vars.Length; ++i)
149 pos [i] = vars [i].GetValueIndex;
150 return vm.DecodeValues (vm.conn.StackFrame_GetValues (thread.Id, Id, pos));
153 public Value GetArgument (int pos) {
154 return GetValue (Method.GetParameters () [pos]);
157 public Value GetThis () {
158 return vm.DecodeValue (vm.conn.StackFrame_GetThis (thread.Id, Id));
161 public void SetValue (LocalVariable var, Value value) {
163 throw new ArgumentNullException ("var");
164 if (var.Method != Method)
165 throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
167 throw new ArgumentNullException ("value");
170 // FIXME: Check for return value
172 vm.conn.StackFrame_SetValues (thread.Id, Id, new int [] { var.GetValueIndex }, new ValueImpl [] { vm.EncodeValue (value) });
173 } catch (CommandException ex) {
174 if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
175 throw new ArgumentException ("Value does not match the type of the local variable.");
181 public void SetValue (ParameterInfoMirror param, Value value) {
183 throw new ArgumentNullException ("param");
184 if (param.Method != Method)
185 throw new ArgumentException ("Parameter doesn't belong to this frame's method.");
187 throw new ArgumentException ("Parameter represents the method return value.");
189 throw new ArgumentNullException ("value");
193 // FIXME: Allow setting the frame return value if possible
195 vm.conn.StackFrame_SetValues (thread.Id, Id, new int [] { (- param.Position) - 1 }, new ValueImpl [] { vm.EncodeValue (value) });
196 } catch (CommandException ex) {
197 if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
198 throw new ArgumentException ("Value does not match the type of the variable.");
204 public IList<LocalVariable> GetVisibleVariables () {
205 if (Location.ILOffset == -1)
206 throw new AbsentInformationException ();
208 return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset).ToList ();
211 public LocalVariable GetVisibleVariableByName (string name) {
213 throw new ArgumentNullException ("name");
215 if (Location.ILOffset == -1)
216 throw new AbsentInformationException ();
218 return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset && l.Name == name).FirstOrDefault ();