|
1 /* |
|
2 * Copyright (c) 2009 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 using System; |
|
18 using System.IO; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using System.Text.RegularExpressions; |
|
22 using SymbianStackLib.Data.Output.Entry; |
|
23 |
|
24 namespace SymbianStackLib.Data.Output |
|
25 { |
|
26 public class StackOutputData : IEnumerable<StackOutputEntry> |
|
27 { |
|
28 #region Delegates & events |
|
29 public delegate void EntryCreatedHandler( StackOutputEntry aEntry ); |
|
30 public event EntryCreatedHandler EntryCreated; |
|
31 #endregion |
|
32 |
|
33 #region Constructors |
|
34 public StackOutputData() |
|
35 { |
|
36 } |
|
37 #endregion |
|
38 |
|
39 #region API |
|
40 public void Clear() |
|
41 { |
|
42 iEntries.Clear(); |
|
43 IsAccurate = false; |
|
44 AlgorithmName = string.Empty; |
|
45 } |
|
46 |
|
47 public string ToString( bool aHideNonSymbols, bool aHideGhosts ) |
|
48 { |
|
49 StringBuilder text = new StringBuilder(); |
|
50 // |
|
51 StackOutputEntry lastElement = null; |
|
52 foreach ( StackOutputEntry element in this ) |
|
53 { |
|
54 bool includeEntry = IncludeEntry( element, aHideNonSymbols, aHideGhosts ); |
|
55 if ( includeEntry ) |
|
56 { |
|
57 if ( lastElement != null && lastElement.IsOutsideCurrentStackRange && element.IsOutsideCurrentStackRange == false && !element.IsRegisterBasedEntry ) |
|
58 { |
|
59 text.Append( System.Environment.NewLine ); |
|
60 text.Append( " >>>> Current Stack Pointer >>>> " + System.Environment.NewLine ); |
|
61 text.Append( System.Environment.NewLine ); |
|
62 } |
|
63 |
|
64 string line = element.ToString() + Environment.NewLine; |
|
65 text.Append( line ); |
|
66 // |
|
67 lastElement = element; |
|
68 } |
|
69 } |
|
70 // |
|
71 return text.ToString(); |
|
72 } |
|
73 |
|
74 internal void InsertAsFirstEntry( StackOutputEntry aEntry ) |
|
75 { |
|
76 iEntries.Insert( 0, aEntry ); |
|
77 |
|
78 if ( EntryCreated != null ) |
|
79 { |
|
80 EntryCreated( aEntry ); |
|
81 } |
|
82 } |
|
83 |
|
84 internal void Add( StackOutputEntry aEntry ) |
|
85 { |
|
86 iEntries.Add( aEntry ); |
|
87 // |
|
88 if ( EntryCreated != null ) |
|
89 { |
|
90 EntryCreated( aEntry ); |
|
91 } |
|
92 } |
|
93 #endregion |
|
94 |
|
95 #region Properties |
|
96 public int Count |
|
97 { |
|
98 get { return iEntries.Count; } |
|
99 } |
|
100 |
|
101 public bool IsAccurate |
|
102 { |
|
103 get { return iIsAccurate; } |
|
104 set { iIsAccurate = value; } |
|
105 } |
|
106 |
|
107 public string AlgorithmName |
|
108 { |
|
109 get { return iAlgorithmName; } |
|
110 set { iAlgorithmName = value; } |
|
111 } |
|
112 |
|
113 public StackOutputEntry this[ int aIndex ] |
|
114 { |
|
115 get { return iEntries[ aIndex ]; } |
|
116 } |
|
117 #endregion |
|
118 |
|
119 #region Internal methods |
|
120 private static bool IncludeEntry( StackOutputEntry aElement, bool aHideNonSymbols, bool aHideGhosts ) |
|
121 { |
|
122 bool passedGhostCheck = true; |
|
123 bool passedNonSymbolCheck = true; |
|
124 |
|
125 // Check whether we should exclude ghosts |
|
126 if ( aHideGhosts ) |
|
127 { |
|
128 if ( aElement.IsGhost ) |
|
129 { |
|
130 // We definitely hide these... |
|
131 passedGhostCheck = false; |
|
132 } |
|
133 else if ( aElement.Symbol == null ) |
|
134 { |
|
135 // We also hide all of these |
|
136 passedGhostCheck = false; |
|
137 } |
|
138 } |
|
139 |
|
140 // Check whether we should exclude symbols which are NULL |
|
141 if ( aHideNonSymbols ) |
|
142 { |
|
143 if ( aElement.Symbol == null && aElement.AssociatedBinary == string.Empty ) |
|
144 { |
|
145 passedNonSymbolCheck = false; |
|
146 } |
|
147 } |
|
148 |
|
149 // Some entries override everything |
|
150 bool ret = ( passedGhostCheck && passedNonSymbolCheck ); |
|
151 if ( aElement.IsCurrentStackPointerEntry || aElement.IsRegisterBasedEntry ) |
|
152 { |
|
153 ret = true; |
|
154 } |
|
155 // |
|
156 return ret; |
|
157 } |
|
158 #endregion |
|
159 |
|
160 #region From IEnumerable<StackOutputEntry> |
|
161 public IEnumerator<StackOutputEntry> GetEnumerator() |
|
162 { |
|
163 foreach ( StackOutputEntry entry in iEntries ) |
|
164 { |
|
165 yield return entry; |
|
166 } |
|
167 } |
|
168 |
|
169 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
170 { |
|
171 foreach ( StackOutputEntry entry in iEntries ) |
|
172 { |
|
173 yield return entry; |
|
174 } |
|
175 } |
|
176 #endregion |
|
177 |
|
178 #region From System.Object |
|
179 public override string ToString() |
|
180 { |
|
181 StringBuilder ret = new StringBuilder(); |
|
182 // |
|
183 foreach ( StackOutputEntry entry in this ) |
|
184 { |
|
185 ret.AppendLine( entry.ToString() ); |
|
186 } |
|
187 // |
|
188 return ret.ToString(); |
|
189 } |
|
190 #endregion |
|
191 |
|
192 #region Data members |
|
193 private bool iIsAccurate = false; |
|
194 private string iAlgorithmName = string.Empty; |
|
195 private List<StackOutputEntry> iEntries = new List<StackOutputEntry>(); |
|
196 #endregion |
|
197 } |
|
198 } |