File: Backtrace.cs

package info (click to toggle)
mono-debugger-libs 0%2B20131201.3459502-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,584 kB
  • sloc: cs: 22,277; makefile: 9; ansic: 7
file content (67 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using Mono.Debugging.Backend;

namespace Mono.Debugging.Client
{
	[Serializable]
	public class Backtrace
	{
		IBacktrace serverBacktrace;
		int count;
		
		[NonSerialized]
		DebuggerSession session;

		List<StackFrame> frames;
		
		public Backtrace (IBacktrace serverBacktrace)
		{
			this.serverBacktrace = serverBacktrace;
			
			count = serverBacktrace.FrameCount;

			// Get some initial frames
			if (count > 0)
				GetFrame (0);
		}
		
		internal void Attach (DebuggerSession session)
		{
			this.session = session;
			serverBacktrace = session.WrapDebuggerObject (serverBacktrace);
			if (frames != null) {
				foreach (StackFrame f in frames) {
					f.Attach (session);
					f.SourceBacktrace = serverBacktrace;
				}
			}
		}

		public int FrameCount
		{
			get { return count; }
		}

		public StackFrame GetFrame (int n)
		{
			if (frames == null)
				frames = new List<StackFrame>();

			if (n >= frames.Count) {
				StackFrame[] newSet = serverBacktrace.GetStackFrames(frames.Count, n + 20);
				foreach (StackFrame sf in newSet) {
					sf.SourceBacktrace = serverBacktrace;
					sf.Index = frames.Count;
					frames.Add (sf);
					sf.Attach (session);
				}
			}
			
			if (frames.Count > 0)
				return frames[System.Math.Min (System.Math.Max (0, n), frames.Count - 1)];

			return null;
		}
	}
}