5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
30
namespace Mono.Debugging.Client
33
public class ExceptionInfo
35
ObjectValue exception;
38
ExceptionStackFrame[] frames;
41
ExceptionInfo innerException;
44
/// The provided value can have the following members:
45
/// Type of the object: type of the exception
46
/// Message: Message of the exception
47
/// Instance: Raw instance of the exception
48
/// StackTrace: an array of frames. Each frame must have:
49
/// Value of the object: display text of the frame
50
/// File: name of the file
53
/// InnerException: inner exception, following the same format described above.
55
public ExceptionInfo (ObjectValue exception)
57
this.exception = exception;
58
if (exception.IsEvaluating || exception.IsEvaluatingGroup)
59
exception.ValueChanged += HandleExceptionValueChanged;
63
void HandleExceptionValueChanged (object sender, EventArgs e)
66
if (exception.IsEvaluatingGroup)
67
exception = exception.GetArrayItem (0);
74
Changed (this, EventArgs.Empty);
78
get { return exception.TypeName; }
81
public string Message {
83
ObjectValue val = exception.GetChild ("Message");
84
return val != null ? val.Value : null;
88
public ObjectValue Instance {
90
return exception.GetChild ("Instance");
94
public ExceptionStackFrame[] StackTrace {
99
ObjectValue stackTrace = exception.GetChild ("StackTrace");
100
if (stackTrace == null)
101
return frames = new ExceptionStackFrame [0];
103
if (stackTrace.IsEvaluating) {
104
frames = new ExceptionStackFrame [0];
105
stackTrace.ValueChanged += HandleExceptionValueChanged;
108
List<ExceptionStackFrame> list = new List<ExceptionStackFrame> ();
109
foreach (ObjectValue val in stackTrace.GetAllChildren ())
110
list.Add (new ExceptionStackFrame (val));
111
frames = list.ToArray ();
116
public ExceptionInfo InnerException {
118
if (innerException == null) {
119
ObjectValue innerVal = exception.GetChild ("InnerException");
120
if (innerVal == null || innerVal.IsError || innerVal.IsUnknown)
122
if (innerVal.IsEvaluating) {
123
innerVal.ValueChanged += delegate { NotifyChanged (); };
126
innerException = new ExceptionInfo (innerVal);
127
innerException.Changed += delegate {
131
return innerException;
135
public event EventHandler Changed;
137
internal void ConnectCallback (StackFrame parentFrame)
139
ObjectValue.ConnectCallbacks (parentFrame, exception);
143
public class ExceptionStackFrame
148
/// The provided value must have a specific structure.
149
/// The Value property is the display text.
150
/// A child "File" member must be the name of the file.
151
/// A child "Line" member must be the line.
152
/// A child "Col" member must be the column.
154
public ExceptionStackFrame (ObjectValue value)
161
ObjectValue file = frame.GetChild ("File");
171
ObjectValue val = frame.GetChild ("Line");
173
return int.Parse (val.Value);
181
ObjectValue val = frame.GetChild ("Column");
183
return int.Parse (val.Value);
189
public string DisplayText {
190
get { return frame.Value; }