File: TargetException.cs

package info (click to toggle)
mono-debugger 0.60%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,556 kB
  • ctags: 22,787
  • sloc: ansic: 99,407; cs: 42,429; sh: 9,192; makefile: 376
file content (160 lines) | stat: -rw-r--r-- 4,354 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Runtime.Serialization;

namespace Mono.Debugger
{
	#region Keep in sync with ServerCommandError in backends/server/server.h
	[Serializable]
	public enum TargetError {
		None			= 0,

		UnknownError		= 1,
		InternalError,
		NoTarget,
		AlreadyHaveTarget,
		CannotStartTarget,
		NotStopped,
		AlreadyStopped,
		RecursiveCall,
		NoSuchBreakpoint,
		NoSuchRegister,
		DebugRegisterOccupied,
		MemoryAccess,
		NotImplemented,
		IOError,
		NoCallbackFrame,

		NoStack			= 101,
		NoMethod,
		MethodNotLoaded,
		ClassNotInitialized,
		AlreadyHaveBreakpoint,
		SymbolTable,
		InvocationException,
		LocationInvalid,
		CannotDetach
	}
	#endregion

	[Serializable]
	public class TargetException : Exception, ISerializable
	{
		public readonly TargetError Type;

		public TargetException (TargetError type, string message)
			: base (message)
		{
			this.Type = type;
		}

		public TargetException (TargetError type, string format,
					params object[] args)
			: this (type, String.Format (format, args))
		{ }

		public TargetException (TargetError type)
			: this (type, GetMessage (type))
		{ }

		protected static string GetMessage (TargetError type)
		{
			switch (type) {
			case TargetError.UnknownError:
				return "Unknown error.";
			case TargetError.NoTarget:
				return "No target.";
			case TargetError.AlreadyHaveTarget:
				return "Already have a program to debug.";
			case TargetError.CannotStartTarget:
				return "Cannot start target.";
			case TargetError.NotStopped:
				return "The target is currently running, but it must be " +
					"stopped to perform the requested operation.";
			case TargetError.AlreadyStopped:
				return "The target is already stopped.";
			case TargetError.RecursiveCall:
				return "Internal error: recursive call";
			case TargetError.NoSuchBreakpoint:
				return "No such breakpoint.";
			case TargetError.NoSuchRegister:
				return "No such register.";
			case TargetError.DebugRegisterOccupied:
				return "Cannot insert hardware breakpoint/watchpoint: " +
					"all debugging registers are already occupied.";
			case TargetError.MemoryAccess:
				return "Memory access.";
			case TargetError.NotImplemented:
				return "Requested feature not implemented on this platform.";
			case TargetError.IOError:
				return "Unknown I/O error.";
			case TargetError.NoStack:
				return "No stack.";
			case TargetError.NoMethod:
				return "Cannot get bounds of current method.";
			case TargetError.MethodNotLoaded:
				return "Method not loaded.";
			case TargetError.ClassNotInitialized:
				return "Class not initialized.";
			case TargetError.AlreadyHaveBreakpoint:
				return "Already have a breakpoint at this location.";
			case TargetError.SymbolTable:
				return "Symbol table error.";
			case TargetError.InvocationException:
				return "Error while invoking a method in the target.";
			case TargetError.LocationInvalid:
				return "Location is invalid.";
			case TargetError.CannotDetach:
				return "Cannot detach from this target because we did not " +
					"attach to it.";
			default:
				return "Unknown error";
			}
		}

		protected TargetException (SerializationInfo info, StreamingContext context)
			: base (info, context)
		{
			Type = (TargetError) info.GetValue ("Type", typeof (TargetError));
		}

                public override void GetObjectData (SerializationInfo info, StreamingContext context)
		{
			info.AddValue ("Type", Type);
			base.GetObjectData (info, context);
		}
	}

	[Serializable]
	public class LocationInvalidException : TargetException
	{
		public LocationInvalidException ()
			: this ("Location is invalid.")
		{ }

		public LocationInvalidException (string message)
			: base (TargetError.LocationInvalid, message)
		{ }

		public LocationInvalidException (TargetException ex)
			: this (GetExceptionText (ex))
		{ }

		protected static string GetExceptionText (TargetException ex)
		{
			if ((ex is TargetMemoryException) || (ex is LocationInvalidException))
				return ex.Message;
			else
				return String.Format ("{0}: {1}", ex.GetType ().Name, ex.Message);
		}

		protected LocationInvalidException (SerializationInfo info, StreamingContext context)
			: base (info, context)
		{
		}

                public override void GetObjectData (SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData (info, context);
		}
	}
}