|
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.Collections.Generic; |
|
19 using System.IO; |
|
20 using SymbianDebugLib.PluginAPI.Types.Symbol; |
|
21 using SymbianStructuresLib.CodeSegments; |
|
22 using SymbianStructuresLib.Debug.Common.FileName; |
|
23 using SymbianStructuresLib.Debug.Symbols; |
|
24 using SymbianSymbolLib.QueryAPI; |
|
25 using SymbianSymbolLib.Relocator; |
|
26 using SymbianSymbolLib.SourceManagement.Source; |
|
27 using SymbianUtils.FileSystem.FilePair; |
|
28 |
|
29 namespace SymbianSymbolLib.DbgEnginePlugin |
|
30 { |
|
31 internal class SymbolView : DbgViewSymbol |
|
32 { |
|
33 #region Constructors |
|
34 public SymbolView( string aName, SymbolPlugin aPlugin ) |
|
35 : base( aName, aPlugin ) |
|
36 { |
|
37 iRelocator = new SymbolRelocator( aPlugin ); |
|
38 iQueryAPI = new SymbolQueryAPI( iRelocator ); |
|
39 } |
|
40 #endregion |
|
41 |
|
42 #region From DbgPluginView |
|
43 public override bool Contains( uint aAddress ) |
|
44 { |
|
45 bool ret = iQueryAPI.Contains( aAddress ); |
|
46 return ret; |
|
47 } |
|
48 |
|
49 public override bool Activate( CodeSegDefinition aCodeSegment ) |
|
50 { |
|
51 bool activated = ActivateAndGetCollection( aCodeSegment ) != null; |
|
52 return activated; |
|
53 } |
|
54 |
|
55 public override bool Deactivate( CodeSegDefinition aCodeSegment ) |
|
56 { |
|
57 return iRelocator.Deactivate( aCodeSegment ); |
|
58 } |
|
59 |
|
60 public override bool SerializeTaggedCollections( FileNamePairCollection aFilesToSave ) |
|
61 { |
|
62 int initialFileCount = aFilesToSave.Count; |
|
63 |
|
64 // Will contain tagged fixed collections |
|
65 SymbolCollectionList symColFixed = new SymbolCollectionList(); |
|
66 |
|
67 // Will contain dynamically relocated collections |
|
68 SymbolCollectionList symColDynamicRelocations = new SymbolCollectionList(); |
|
69 |
|
70 // Find tagged collections |
|
71 string fixedSymbolCollectionFileName = string.Empty; |
|
72 SymSourceManager sourceManager = iQueryAPI.SourceManager; |
|
73 foreach ( SymSource source in sourceManager ) |
|
74 { |
|
75 int count = source.Count; |
|
76 for( int i=0; i<count; i++ ) |
|
77 { |
|
78 SymbolCollection col = source[ i ]; |
|
79 if ( col.Tagged ) |
|
80 { |
|
81 if ( col.IsFixed ) |
|
82 { |
|
83 symColFixed.Add( col ); |
|
84 |
|
85 // Save the ROM symbol file name (if present) |
|
86 if ( string.IsNullOrEmpty( fixedSymbolCollectionFileName ) ) |
|
87 { |
|
88 fixedSymbolCollectionFileName = source.FileName; |
|
89 } |
|
90 } |
|
91 else |
|
92 { |
|
93 symColDynamicRelocations.Add( col ); |
|
94 } |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 // Now save them to needed files. We create one file for all the fixed |
|
100 // collections and then individual files for all the dynamically relocated |
|
101 // collections. |
|
102 // |
|
103 // In all cases, we create temporary files which are to be deleted by |
|
104 // the client. |
|
105 if ( symColFixed.Count > 0 ) |
|
106 { |
|
107 SerializeCollection( aFilesToSave, Path.GetFileNameWithoutExtension( fixedSymbolCollectionFileName ) + ".symbol", symColFixed ); |
|
108 } |
|
109 if ( symColDynamicRelocations.Count > 0 ) |
|
110 { |
|
111 foreach ( SymbolCollection col in symColDynamicRelocations ) |
|
112 { |
|
113 // For the dynamically relocated collections, we must generate a file name based |
|
114 // upon the collection details. |
|
115 string fileName = Path.GetFileNameWithoutExtension( col.FileName.EitherFullNameButDevicePreferred ) + ".symbol"; |
|
116 SerializeCollection( aFilesToSave, fileName, col ); |
|
117 } |
|
118 } |
|
119 |
|
120 return ( aFilesToSave.Count != initialFileCount ); |
|
121 } |
|
122 |
|
123 public override bool IsReady |
|
124 { |
|
125 get |
|
126 { |
|
127 // For a view to be ready we must have at least one |
|
128 // activated, i.e. 'ready' symbol source. |
|
129 int count = 0; |
|
130 |
|
131 // Check with dynamic activations |
|
132 foreach ( SymSourceAndCollection pair in iRelocator ) |
|
133 { |
|
134 if ( pair.Source.TimeToRead == SymSource.TTimeToRead.EReadWhenPriming ) |
|
135 { |
|
136 ++count; |
|
137 break; // No need to count anymore |
|
138 } |
|
139 } |
|
140 |
|
141 // Try to find any fixed activation entries |
|
142 if ( count == 0 ) |
|
143 { |
|
144 SymSourceManager allSources = this.SourceManager; |
|
145 foreach ( SymSource source in allSources ) |
|
146 { |
|
147 count += source.CountActivated; |
|
148 if ( count > 0 ) |
|
149 { |
|
150 break; |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 return ( count > 0 ); |
|
156 } |
|
157 } |
|
158 #endregion |
|
159 |
|
160 #region From DbgViewSymbols |
|
161 public override Symbol Lookup( uint aAddress, out SymbolCollection aCollection ) |
|
162 { |
|
163 Symbol ret = iQueryAPI.Lookup( aAddress, out aCollection ); |
|
164 return ret; |
|
165 } |
|
166 |
|
167 public override SymbolCollection CollectionByAddress( uint aAddress ) |
|
168 { |
|
169 SymbolCollection ret = iQueryAPI.CollectionByAddress( aAddress ); |
|
170 return ret; |
|
171 } |
|
172 |
|
173 public override SymbolCollection ActivateAndGetCollection( CodeSegDefinition aCodeSegment ) |
|
174 { |
|
175 SymbolCollection ret = iRelocator.Activate( aCodeSegment ); |
|
176 return ret; |
|
177 } |
|
178 |
|
179 public override SymbolCollection this[ CodeSegDefinition aCodeSeg ] |
|
180 { |
|
181 get |
|
182 { |
|
183 SymbolCollection ret = iQueryAPI[ aCodeSeg ]; |
|
184 return ret; |
|
185 } |
|
186 } |
|
187 |
|
188 public override SymbolCollection this[ PlatformFileName aFileName ] |
|
189 { |
|
190 get |
|
191 { |
|
192 SymbolCollection ret = iQueryAPI[ aFileName ]; |
|
193 return ret; |
|
194 } |
|
195 } |
|
196 |
|
197 protected override IEnumerator<SymbolCollection> GetEnumeratorSymbolCollection() |
|
198 { |
|
199 return iQueryAPI.GetEnumerator(); |
|
200 } |
|
201 #endregion |
|
202 |
|
203 #region API |
|
204 #endregion |
|
205 |
|
206 #region Properties |
|
207 internal SymbolPlugin Plugin |
|
208 { |
|
209 get { return base.Engine as SymbolPlugin; } |
|
210 } |
|
211 |
|
212 internal SymbolQueryAPI QueryAPI |
|
213 { |
|
214 get { return iQueryAPI; } |
|
215 } |
|
216 |
|
217 internal SymSourceManager SourceManager |
|
218 { |
|
219 get { return Plugin.SourceManager; } |
|
220 } |
|
221 #endregion |
|
222 |
|
223 #region Internal methods |
|
224 private void SerializeCollection( FileNamePairCollection aFilesToSave, string aProposedFileName, SymbolCollection aCollection ) |
|
225 { |
|
226 SymbolCollectionList list = new SymbolCollectionList(); |
|
227 list.Add( aCollection ); |
|
228 SerializeCollection( aFilesToSave, aProposedFileName, list ); |
|
229 } |
|
230 |
|
231 private void SerializeCollection( FileNamePairCollection aFilesToSave, string aProposedFileName, SymbolCollectionList aList ) |
|
232 { |
|
233 string tempFileName = Path.GetTempFileName(); |
|
234 // |
|
235 FileNamePair fileNamePair = new FileNamePair( tempFileName ); |
|
236 fileNamePair.Destination = string.Format( "/Symbols/{0}", Path.GetFileName( aProposedFileName ) ); |
|
237 fileNamePair.DeleteFile = true; |
|
238 |
|
239 // Make sure the collections are sorted in order |
|
240 aList.SortByCollectionAddress(); |
|
241 |
|
242 using ( FileStream stream = new FileStream( tempFileName, FileMode.Create ) ) |
|
243 { |
|
244 aList.Serialize( stream ); |
|
245 } |
|
246 // |
|
247 aFilesToSave.Add( fileNamePair ); |
|
248 } |
|
249 #endregion |
|
250 |
|
251 #region Data members |
|
252 private readonly SymbolQueryAPI iQueryAPI; |
|
253 private readonly SymbolRelocator iRelocator; |
|
254 #endregion |
|
255 } |
|
256 } |