|
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 SymbianParserLib.Engine; |
|
22 using SymbianParserLib.BaseStructures; |
|
23 using CrashDebuggerLib.Structures.Scheduler; |
|
24 using CrashDebuggerLib.Structures.Register; |
|
25 using CrashDebuggerLib.Structures.UserContextTable; |
|
26 using SymbianParserLib.Elements; |
|
27 using SymbianParserLib.Enums; |
|
28 |
|
29 namespace CrashDebuggerLib.Parsers.State.Implementation |
|
30 { |
|
31 internal class StateInfoUserContextTable : State |
|
32 { |
|
33 #region Constructors |
|
34 public StateInfoUserContextTable( CrashDebuggerParser aParser ) |
|
35 : base( aParser ) |
|
36 { |
|
37 } |
|
38 #endregion |
|
39 |
|
40 #region API |
|
41 public override void Prepare() |
|
42 { |
|
43 ParserParagraph para = new ParserParagraph( "USERCONTEXTTABLE_INFO" ); |
|
44 |
|
45 // The format of the actual entry specification is the same for each |
|
46 // line |
|
47 StringBuilder lineFormat = new StringBuilder( ); |
|
48 int count = UserContextTable.EntryCount; |
|
49 for( int i=0; i<count; i++ ) |
|
50 { |
|
51 lineFormat.Append( "[%02x, %02x]" ); |
|
52 } |
|
53 |
|
54 // Create one line per table |
|
55 int tableCount = CrashDebugger.UserContextTableManager.Count; |
|
56 for( int i=0; i<tableCount; i++ ) |
|
57 { |
|
58 // Create line based upon dynamic format string |
|
59 string format = String.Format( KTablePrefixFormat, i, lineFormat.ToString() ); |
|
60 ParserLine line = ParserLine.NewSymFormat( format ); |
|
61 |
|
62 // Save the context table type - we need this in the callback later on |
|
63 line.Tag = (TUserContextType) i; |
|
64 |
|
65 // Make sure each field stores it's value internally, so that we can extract it |
|
66 // ourselves in the callback. |
|
67 line.SetTargetObject(); |
|
68 |
|
69 // Get a callback when all fields are ready. |
|
70 line.ElementComplete += new ParserElementBase.ElementCompleteHandler( LineComplete ); |
|
71 |
|
72 para.Add( line ); |
|
73 } |
|
74 |
|
75 ParserEngine.Add( para ); |
|
76 } |
|
77 |
|
78 public override void Finalise() |
|
79 { |
|
80 // Go through each field |
|
81 CrashDebugger.UserContextTableManager.Dump(); |
|
82 } |
|
83 #endregion |
|
84 |
|
85 #region Properties |
|
86 #endregion |
|
87 |
|
88 #region Internal methods |
|
89 void LineComplete( ParserElementBase aElement ) |
|
90 { |
|
91 ParserLine line = (ParserLine) aElement; |
|
92 TUserContextType tableType = (TUserContextType) line.Tag; |
|
93 UserContextTable table = CrashDebugger.UserContextTableManager[ tableType ]; |
|
94 |
|
95 // Each line should have a known number of entries stored within it's field collection. |
|
96 int expectedCount = UserContextTable.EntryCount * 2; // 2 fields per table entry |
|
97 int actualCount = line.Count; |
|
98 |
|
99 if ( expectedCount == actualCount ) |
|
100 { |
|
101 for ( int i = 0; i < expectedCount; i += 2 ) |
|
102 { |
|
103 ParserField fieldType = line[ i + 0 ]; |
|
104 ParserField fieldValue = line[ i + 1 ]; |
|
105 // |
|
106 if ( fieldType.IsUint && fieldValue.IsUint ) |
|
107 { |
|
108 UserContextTable.TArmRegisterIndex reg = (UserContextTable.TArmRegisterIndex) ( i / 2 ); |
|
109 UserContextTableEntry entry = table[ reg ]; |
|
110 // |
|
111 UserContextTableEntry.TType type = (UserContextTableEntry.TType) fieldType.AsUint; |
|
112 byte value = (byte) fieldValue.AsUint; |
|
113 // |
|
114 entry.Type = type; |
|
115 entry.Offset = value; |
|
116 } |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 throw new Exception( "User Context Table Corruption" ); |
|
122 } |
|
123 } |
|
124 #endregion |
|
125 |
|
126 #region Internal constants |
|
127 private const string KTablePrefixFormat = "Table[{0:d2}] = {1}"; |
|
128 #endregion |
|
129 |
|
130 #region Data members |
|
131 private List<ParserLine> iLines = new List<ParserLine>(); |
|
132 #endregion |
|
133 } |
|
134 } |