|
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 System.IO; |
|
22 using SymbianUtils; |
|
23 using SymbianUtils.Tracer; |
|
24 using SymbianUtils.FileTypes; |
|
25 using SymbianStructuresLib.Debug.Symbols; |
|
26 using SymbianStructuresLib.CodeSegments; |
|
27 using SymbianStructuresLib.Debug.Common.FileName; |
|
28 using SymbianSymbolLib.SourceManagement.Source; |
|
29 using SymbianSymbolLib.Relocator; |
|
30 |
|
31 namespace SymbianSymbolLib.QueryAPI |
|
32 { |
|
33 internal class SymbolQueryAPI : IEnumerable<SymbolCollection> |
|
34 { |
|
35 #region Constructors |
|
36 internal SymbolQueryAPI( SymbolRelocator aRelocator ) |
|
37 { |
|
38 iRelocator = aRelocator; |
|
39 } |
|
40 #endregion |
|
41 |
|
42 #region API |
|
43 public bool Contains( uint aAddress ) |
|
44 { |
|
45 // First check with the relocated/activated symbol collections, |
|
46 // i.e. RAM-loaded code that has been fixed up. |
|
47 bool ret = iRelocator.CollectionList.Contains( aAddress ); |
|
48 if ( ret == false ) |
|
49 { |
|
50 // Wasn't a relocated symbol collection, so search through |
|
51 // all sources for ROM/XIP symbols that might match. |
|
52 foreach ( SymSource source in SourceManager ) |
|
53 { |
|
54 if ( source.Contains( aAddress ) ) |
|
55 { |
|
56 ret = true; |
|
57 break; |
|
58 } |
|
59 } |
|
60 } |
|
61 // |
|
62 return ret; |
|
63 } |
|
64 |
|
65 public Symbol Lookup( uint aAddress, out SymbolCollection aCollection ) |
|
66 { |
|
67 aCollection = null; |
|
68 |
|
69 // First check with the relocated/activated symbol collections, |
|
70 // i.e. RAM-loaded code that has been fixed up. |
|
71 Symbol ret = iRelocator.CollectionList.Lookup( aAddress, out aCollection ); |
|
72 if ( ret == null && aCollection == null ) |
|
73 { |
|
74 foreach ( SymSource source in SourceManager ) |
|
75 { |
|
76 if ( source.Contains( aAddress ) ) |
|
77 { |
|
78 ret = source.Lookup( aAddress, out aCollection ); |
|
79 break; |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 // Tag the collection because it provided a symbol |
|
85 if ( aCollection != null ) |
|
86 { |
|
87 aCollection.Tagged = true; |
|
88 } |
|
89 |
|
90 return ret; |
|
91 } |
|
92 |
|
93 public SymbolCollection CollectionByAddress( uint aAddress ) |
|
94 { |
|
95 SymbolCollection collection = null; |
|
96 Symbol symbol = Lookup( aAddress, out collection ); |
|
97 return collection; |
|
98 } |
|
99 #endregion |
|
100 |
|
101 #region Properties |
|
102 public Symbol this[ uint aAddress ] |
|
103 { |
|
104 get |
|
105 { |
|
106 SymbolCollection collection = null; |
|
107 Symbol ret = Lookup( aAddress, out collection ); |
|
108 return ret; |
|
109 } |
|
110 } |
|
111 |
|
112 public SymbolCollection this[ CodeSegDefinition aCodeSeg ] |
|
113 { |
|
114 get |
|
115 { |
|
116 SymbolCollection ret = null; |
|
117 SymSourceAndCollection pair = SourceManager[ aCodeSeg ]; |
|
118 if ( pair != null ) |
|
119 { |
|
120 ret = pair.Collection; |
|
121 } |
|
122 return ret; |
|
123 } |
|
124 } |
|
125 |
|
126 public SymbolCollection this[ PlatformFileName aFileName ] |
|
127 { |
|
128 get |
|
129 { |
|
130 SymbolCollection ret = null; |
|
131 // |
|
132 foreach ( SymSource source in SourceManager ) |
|
133 { |
|
134 SymbolCollection col = source[ aFileName ]; |
|
135 if ( col != null ) |
|
136 { |
|
137 ret = col; |
|
138 break; |
|
139 } |
|
140 } |
|
141 // |
|
142 return ret; |
|
143 } |
|
144 } |
|
145 #endregion |
|
146 |
|
147 #region Internal methods |
|
148 internal SymSourceManager SourceManager |
|
149 { |
|
150 get { return iRelocator.SourceManager; } |
|
151 } |
|
152 #endregion |
|
153 |
|
154 #region Internal enumerator |
|
155 #endregion |
|
156 |
|
157 #region From IEnumerable<SymbolCollection> |
|
158 public IEnumerator<SymbolCollection> GetEnumerator() |
|
159 { |
|
160 // This gives us explicit activations |
|
161 SymbolCollectionList list = iRelocator.CollectionList; |
|
162 foreach ( SymbolCollection col in list ) |
|
163 { |
|
164 yield return col; |
|
165 } |
|
166 |
|
167 // Next we need fixed collections |
|
168 IEnumerable<SymbolCollection> fixedCols = iRelocator.SourceManager.GetFixedCollectionEnumerator(); |
|
169 foreach ( SymbolCollection col in fixedCols ) |
|
170 { |
|
171 if ( col.IsFixed ) |
|
172 { |
|
173 yield return col; |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
179 { |
|
180 // This gives us explicit activations |
|
181 SymbolCollectionList list = iRelocator.CollectionList; |
|
182 foreach ( SymbolCollection col in list ) |
|
183 { |
|
184 yield return col; |
|
185 } |
|
186 |
|
187 // Next we need fixed collections |
|
188 IEnumerable<SymbolCollection> fixedCols = iRelocator.SourceManager.GetFixedCollectionEnumerator(); |
|
189 foreach ( SymbolCollection col in fixedCols ) |
|
190 { |
|
191 if ( col.IsFixed ) |
|
192 { |
|
193 yield return col; |
|
194 } |
|
195 } |
|
196 } |
|
197 #endregion |
|
198 |
|
199 #region Data members |
|
200 private readonly SymbolRelocator iRelocator; |
|
201 #endregion |
|
202 } |
|
203 } |