|
1 /* |
|
2 * Copyright (c) 2004-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 using System; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using CrashDebuggerLib.Structures.KernelObjects; |
|
22 using CrashDebuggerLib.Structures.CodeSeg; |
|
23 using CrashDebuggerLib.Structures.Common; |
|
24 using CrashDebuggerLib.Structures.Library; |
|
25 |
|
26 namespace CrashDebuggerLib.Structures.Process |
|
27 { |
|
28 public class ProcessCodeSeg : CrashDebuggerAware |
|
29 { |
|
30 #region Constructors |
|
31 public ProcessCodeSeg( CrashDebuggerInfo aCrashDebugger ) |
|
32 : this( aCrashDebugger, 0, 0 ) |
|
33 { |
|
34 } |
|
35 |
|
36 public ProcessCodeSeg( CrashDebuggerInfo aCrashDebugger, uint aCodeSegAddress, uint aLibraryAddress ) |
|
37 : base( aCrashDebugger ) |
|
38 { |
|
39 iCodeSegAddress = aCodeSegAddress; |
|
40 iLibraryAddress = aLibraryAddress; |
|
41 } |
|
42 #endregion |
|
43 |
|
44 #region API |
|
45 #endregion |
|
46 |
|
47 #region Properties |
|
48 public uint CodeSegAddress |
|
49 { |
|
50 get { return iCodeSegAddress; } |
|
51 set |
|
52 { |
|
53 iCodeSegAddress = value; |
|
54 CodeSegEntry entry = CodeSeg; |
|
55 } |
|
56 } |
|
57 |
|
58 public CodeSegEntry CodeSeg |
|
59 { |
|
60 get { return CrashDebugger.CodeSegByAddress( CodeSegAddress ); } |
|
61 } |
|
62 |
|
63 public string FileName |
|
64 { |
|
65 get |
|
66 { |
|
67 string ret = string.Empty; |
|
68 if ( CodeSeg != null ) |
|
69 { |
|
70 ret = CodeSeg.FileName; |
|
71 } |
|
72 return ret; |
|
73 } |
|
74 } |
|
75 |
|
76 public uint LibraryAddress |
|
77 { |
|
78 get { return iLibraryAddress; } |
|
79 set { iLibraryAddress = value; } |
|
80 } |
|
81 |
|
82 public DLibrary Library |
|
83 { |
|
84 get { return CrashDebugger.LibraryByAddress( LibraryAddress ); } |
|
85 } |
|
86 |
|
87 public uint Size |
|
88 { |
|
89 get |
|
90 { |
|
91 uint ret = 0; |
|
92 // |
|
93 if ( CodeSeg != null ) |
|
94 { |
|
95 ret = CodeSeg.Size; |
|
96 } |
|
97 // |
|
98 return ret; |
|
99 } |
|
100 set |
|
101 { |
|
102 if ( CodeSeg != null ) |
|
103 { |
|
104 CodeSeg.Size = value; |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 public uint ProcessLocalRunAddress |
|
110 { |
|
111 get { return iProcessLocalRunAddress; } |
|
112 set { iProcessLocalRunAddress = value; } |
|
113 } |
|
114 |
|
115 public uint ProcessLocalRunAddressEnd |
|
116 { |
|
117 get |
|
118 { |
|
119 uint ret = ProcessLocalRunAddress + Size; |
|
120 return ret; |
|
121 } |
|
122 } |
|
123 #endregion |
|
124 |
|
125 #region Internal methods |
|
126 #endregion |
|
127 |
|
128 #region Internal constants |
|
129 #endregion |
|
130 |
|
131 #region From System.Object |
|
132 public override string ToString() |
|
133 { |
|
134 StringBuilder ret = new StringBuilder(); |
|
135 // |
|
136 ret.Append( ProcessLocalRunAddress.ToString( "x8" ) ); |
|
137 if ( Size != 0 ) |
|
138 { |
|
139 ret.Append( "-" ); |
|
140 ret.Append( ProcessLocalRunAddressEnd.ToString( "x8" ) ); |
|
141 } |
|
142 ret.Append( " " ); |
|
143 if ( CodeSeg != null ) |
|
144 { |
|
145 ret.Append( CodeSeg.FileName ); |
|
146 } |
|
147 // |
|
148 return ret.ToString(); |
|
149 } |
|
150 #endregion |
|
151 |
|
152 #region Data members |
|
153 private uint iCodeSegAddress = 0; |
|
154 private uint iLibraryAddress = 0; |
|
155 private uint iProcessLocalRunAddress = 0; |
|
156 #endregion |
|
157 } |
|
158 |
|
159 public class ProcessCodeSegCollection : IEnumerable<ProcessCodeSeg> |
|
160 { |
|
161 #region Constructors |
|
162 public ProcessCodeSegCollection() |
|
163 { |
|
164 } |
|
165 #endregion |
|
166 |
|
167 #region API |
|
168 public void Add( ProcessCodeSeg aCodeSeg ) |
|
169 { |
|
170 if ( !Contains( aCodeSeg.CodeSegAddress ) ) |
|
171 { |
|
172 iEntries.Add( aCodeSeg ); |
|
173 } |
|
174 } |
|
175 |
|
176 public bool Contains( uint aAddress ) |
|
177 { |
|
178 ProcessCodeSeg ret = this[ aAddress ]; |
|
179 bool found = ( ret != null ); |
|
180 return found; |
|
181 } |
|
182 #endregion |
|
183 |
|
184 #region Properties |
|
185 public ProcessCodeSeg this[ int aIndex ] |
|
186 { |
|
187 get { return iEntries[ aIndex ]; } |
|
188 } |
|
189 |
|
190 public ProcessCodeSeg this[ uint aAddress ] |
|
191 { |
|
192 get |
|
193 { |
|
194 ProcessCodeSeg ret = iEntries.Find( delegate( ProcessCodeSeg aEntry ) { return aEntry.CodeSegAddress == aAddress; } ); |
|
195 return ret; |
|
196 } |
|
197 } |
|
198 |
|
199 public int Count |
|
200 { |
|
201 get { return iEntries.Count; } |
|
202 } |
|
203 #endregion |
|
204 |
|
205 #region Internal methods |
|
206 #endregion |
|
207 |
|
208 #region Internal constants |
|
209 #endregion |
|
210 |
|
211 #region From System.Object |
|
212 public override string ToString() |
|
213 { |
|
214 return base.ToString(); |
|
215 } |
|
216 #endregion |
|
217 |
|
218 #region From IEnumerable<ProcessCodeSegCollection> |
|
219 public IEnumerator<ProcessCodeSeg> GetEnumerator() |
|
220 { |
|
221 return new ProcessCodeSegEnumerator( this ); |
|
222 } |
|
223 |
|
224 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
225 { |
|
226 return new ProcessCodeSegEnumerator( this ); |
|
227 } |
|
228 #endregion |
|
229 |
|
230 #region Data members |
|
231 private List<ProcessCodeSeg> iEntries = new List<ProcessCodeSeg>(); |
|
232 #endregion |
|
233 } |
|
234 |
|
235 #region Internal enumerator |
|
236 internal class ProcessCodeSegEnumerator : IEnumerator<ProcessCodeSeg> |
|
237 { |
|
238 #region Constructors |
|
239 public ProcessCodeSegEnumerator( ProcessCodeSegCollection aList ) |
|
240 { |
|
241 iList = aList; |
|
242 } |
|
243 #endregion |
|
244 |
|
245 #region IEnumerator Members |
|
246 public void Reset() |
|
247 { |
|
248 iCurrentIndex = -1; |
|
249 } |
|
250 |
|
251 public object Current |
|
252 { |
|
253 get |
|
254 { |
|
255 return iList[ iCurrentIndex ]; |
|
256 } |
|
257 } |
|
258 |
|
259 public bool MoveNext() |
|
260 { |
|
261 return ( ++iCurrentIndex < iList.Count ); |
|
262 } |
|
263 #endregion |
|
264 |
|
265 #region From IEnumerator<ProcessCodeSeg> |
|
266 ProcessCodeSeg IEnumerator<ProcessCodeSeg>.Current |
|
267 { |
|
268 get { return iList[ iCurrentIndex ]; } |
|
269 } |
|
270 #endregion |
|
271 |
|
272 #region From IDisposable |
|
273 public void Dispose() |
|
274 { |
|
275 } |
|
276 #endregion |
|
277 |
|
278 #region Data members |
|
279 private readonly ProcessCodeSegCollection iList; |
|
280 private int iCurrentIndex = -1; |
|
281 #endregion |
|
282 } |
|
283 #endregion |
|
284 } |