~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/Mono.Debugging/Mono.Debugging.Client/ExceptionInfo.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// ExceptionInfo.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Collections.Generic;
 
29
 
 
30
namespace Mono.Debugging.Client
 
31
{
 
32
        [Serializable]
 
33
        public class ExceptionInfo
 
34
        {
 
35
                ObjectValue exception;
 
36
                
 
37
                [NonSerialized]
 
38
                ExceptionStackFrame[] frames;
 
39
                
 
40
                [NonSerialized]
 
41
                ExceptionInfo innerException;
 
42
                
 
43
                /// <summary>
 
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
 
51
                ///     Line: line
 
52
                ///     Col: column
 
53
                /// InnerException: inner exception, following the same format described above.
 
54
                /// </summary>
 
55
                public ExceptionInfo (ObjectValue exception)
 
56
                {
 
57
                        this.exception = exception;
 
58
                        if (exception.IsEvaluating || exception.IsEvaluatingGroup)
 
59
                                exception.ValueChanged += HandleExceptionValueChanged;
 
60
                                
 
61
                }
 
62
 
 
63
                void HandleExceptionValueChanged (object sender, EventArgs e)
 
64
                {
 
65
                        frames = null;
 
66
                        if (exception.IsEvaluatingGroup)
 
67
                                exception = exception.GetArrayItem (0);
 
68
                        NotifyChanged ();
 
69
                }
 
70
                
 
71
                void NotifyChanged ()
 
72
                {
 
73
                        if (Changed != null)
 
74
                                Changed (this, EventArgs.Empty);
 
75
                }
 
76
                
 
77
                public string Type {
 
78
                        get { return exception.TypeName; }
 
79
                }
 
80
 
 
81
                public string Message {
 
82
                        get {
 
83
                                ObjectValue val = exception.GetChild ("Message");
 
84
                                return val != null ? val.Value : null;
 
85
                        }
 
86
                }
 
87
 
 
88
                public ObjectValue Instance {
 
89
                        get {
 
90
                                return exception.GetChild ("Instance");
 
91
                        }
 
92
                }
 
93
 
 
94
                public ExceptionStackFrame[] StackTrace {
 
95
                        get {
 
96
                                if (frames != null)
 
97
                                        return frames;
 
98
                                
 
99
                                ObjectValue stackTrace = exception.GetChild ("StackTrace");
 
100
                                if (stackTrace == null)
 
101
                                        return frames = new ExceptionStackFrame [0];
 
102
                                
 
103
                                if (stackTrace.IsEvaluating) {
 
104
                                        frames = new ExceptionStackFrame [0];
 
105
                                        stackTrace.ValueChanged += HandleExceptionValueChanged;
 
106
                                        return frames;
 
107
                                }
 
108
                                List<ExceptionStackFrame> list = new List<ExceptionStackFrame> ();
 
109
                                foreach (ObjectValue val in stackTrace.GetAllChildren ())
 
110
                                        list.Add (new ExceptionStackFrame (val));
 
111
                                frames = list.ToArray ();
 
112
                                return frames;
 
113
                        }
 
114
                }
 
115
                
 
116
                public ExceptionInfo InnerException {
 
117
                        get {
 
118
                                if (innerException == null) {
 
119
                                        ObjectValue innerVal = exception.GetChild ("InnerException");
 
120
                                        if (innerVal == null || innerVal.IsError || innerVal.IsUnknown)
 
121
                                                return null;
 
122
                                        if (innerVal.IsEvaluating) {
 
123
                                                innerVal.ValueChanged += delegate { NotifyChanged (); };
 
124
                                                return null;
 
125
                                        }
 
126
                                        innerException = new ExceptionInfo (innerVal);
 
127
                                        innerException.Changed += delegate {
 
128
                                                NotifyChanged ();
 
129
                                        };
 
130
                                }
 
131
                                return innerException;
 
132
                        }
 
133
                }
 
134
                
 
135
                public event EventHandler Changed;
 
136
                
 
137
                internal void ConnectCallback (StackFrame parentFrame)
 
138
                {
 
139
                        ObjectValue.ConnectCallbacks (parentFrame, exception);
 
140
                }
 
141
        }
 
142
        
 
143
        public class ExceptionStackFrame
 
144
        {
 
145
                ObjectValue frame;
 
146
                
 
147
                /// <summary>
 
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.
 
153
                /// </summary>
 
154
                public ExceptionStackFrame (ObjectValue value)
 
155
                {
 
156
                        frame = value;
 
157
                }
 
158
 
 
159
                public string File {
 
160
                        get {
 
161
                                ObjectValue file = frame.GetChild ("File");
 
162
                                if (file != null)
 
163
                                        return file.Value;
 
164
                                else
 
165
                                        return null;
 
166
                        }
 
167
                }
 
168
 
 
169
                public int Line {
 
170
                        get {
 
171
                                ObjectValue val = frame.GetChild ("Line");
 
172
                                if (val != null)
 
173
                                        return int.Parse (val.Value);
 
174
                                else
 
175
                                        return 0;
 
176
                        }
 
177
                }
 
178
 
 
179
                public int Column {
 
180
                        get {
 
181
                                ObjectValue val = frame.GetChild ("Column");
 
182
                                if (val != null)
 
183
                                        return int.Parse (val.Value);
 
184
                                else
 
185
                                        return 0;
 
186
                        }
 
187
                }
 
188
 
 
189
                public string DisplayText {
 
190
                        get { return frame.Value; }
 
191
                }
 
192
        }
 
193
}
 
194