|
1 /* |
|
2 * Copyright (c) 1995-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 the License "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 |
|
19 #include <new> |
|
20 #include <iostream> |
|
21 #include <fstream> |
|
22 #include <string> |
|
23 #include <boost/regex.hpp> |
|
24 using namespace std; |
|
25 |
|
26 #include "loggingexception.h" |
|
27 #include "logparser.h" |
|
28 |
|
29 |
|
30 LogParser* LogParser::Only = (LogParser*)0; |
|
31 |
|
32 |
|
33 LogParser* LogParser::GetInstance(TImageType aImageType) throw (LoggingException) |
|
34 { |
|
35 if(! LogParser::Only) |
|
36 { |
|
37 if(aImageType == ERomImage) |
|
38 { |
|
39 LogParser::Only = new (std::nothrow) RomLogParser(); |
|
40 } |
|
41 else if(aImageType == ERofsImage) |
|
42 { |
|
43 LogParser::Only = new (std::nothrow) RofsLogParser(); |
|
44 } |
|
45 else |
|
46 { |
|
47 throw LoggingException(LoggingException::UNKNOWN_IMAGE_TYPE); |
|
48 } |
|
49 if(! LogParser::Only) |
|
50 throw LoggingException(LoggingException::RESOURCE_ALLOCATION_FAILURE); |
|
51 } |
|
52 |
|
53 return LogParser::Only; |
|
54 } |
|
55 |
|
56 void LogParser::Cleanup(void) |
|
57 { |
|
58 return; |
|
59 } |
|
60 |
|
61 |
|
62 LogParser::LogParser(void) |
|
63 { |
|
64 iImageType = EUnknownType; |
|
65 return; |
|
66 } |
|
67 |
|
68 RofsLogParser::RofsLogParser() |
|
69 { |
|
70 iImageType = ERofsImage; |
|
71 } |
|
72 |
|
73 void RofsLogParser::ParseSymbol(const char* LogFilename) throw (LoggingException) |
|
74 { |
|
75 string linebuf; |
|
76 SymbolGenerator* symgen = SymbolGenerator::GetInstance(); |
|
77 symgen->SetImageType(iImageType); |
|
78 symgen->SetSymbolFileName(string(LogFilename)); |
|
79 |
|
80 ifstream logfd(LogFilename); |
|
81 if(logfd.is_open()) |
|
82 { |
|
83 while(! logfd.eof()) |
|
84 { |
|
85 getline(logfd, linebuf); |
|
86 if(linebuf.compare(0,4,"File") == 0) |
|
87 { |
|
88 if(linebuf.find("size:", 4) != string::npos) |
|
89 { |
|
90 size_t startpos = linebuf.find('\'') ; |
|
91 size_t endpos = linebuf.rfind('\''); |
|
92 if((startpos!=string::npos) && (endpos!=string::npos)) |
|
93 { |
|
94 symgen->AddFile(linebuf.substr(startpos+1,endpos-startpos-1), false); |
|
95 } |
|
96 } |
|
97 } |
|
98 else if(linebuf.compare(0,26,"Compressed executable File") == 0) |
|
99 { |
|
100 if(linebuf.find("size:", 26) != string::npos) |
|
101 { |
|
102 size_t startpos = linebuf.find('\'') ; |
|
103 size_t endpos = linebuf.rfind('\''); |
|
104 if((startpos!=string::npos) && (endpos!=string::npos)) |
|
105 { |
|
106 symgen->AddFile(linebuf.substr(startpos+1,endpos-startpos-1), true); |
|
107 } |
|
108 } |
|
109 } |
|
110 } |
|
111 symgen->SetFinished(); |
|
112 symgen->Release(); |
|
113 } |
|
114 else |
|
115 { |
|
116 throw LoggingException(LoggingException::INVALID_LOG_FILENAME); |
|
117 } |
|
118 |
|
119 return; |
|
120 } |
|
121 |
|
122 RomLogParser::RomLogParser() |
|
123 { |
|
124 iImageType = ERomImage; |
|
125 } |
|
126 |
|
127 void RomLogParser::ParseSymbol(const char* LogFilename) throw (LoggingException) |
|
128 { |
|
129 string linebuf; |
|
130 SymbolGenerator* symgen = SymbolGenerator::GetInstance(); |
|
131 symgen->SetImageType(iImageType); |
|
132 symgen->SetSymbolFileName(string(LogFilename)); |
|
133 |
|
134 ifstream logfd(LogFilename); |
|
135 if(logfd.is_open()) |
|
136 { |
|
137 //boost::regex beginFlag("^Creating Rom image (\\S*)"); |
|
138 boost::regex endFlag("^Writing Rom image"); |
|
139 boost::regex sourceFile("^Reading resource (.*) to rom linear address (.*)"); |
|
140 boost::regex executableFile("^Processing file (.*)"); |
|
141 boost::regex codeStart("^Code start addr:\\s*(\\w+)"); |
|
142 boost::regex dataStart("^Data start addr:\\s+(\\w+)"); |
|
143 boost::regex dataBssStart("^DataBssLinearBase:\\s+(\\w+)"); |
|
144 boost::regex textSize("^Text size:\\s+(\\w+)"); |
|
145 boost::regex dataSize("^Data size:\\s+(\\w+)"); |
|
146 boost::regex bssSize("Bsssize:\\s+(\\w+)"); |
|
147 boost::regex totalDataSize("^Total data size:\\s+(\\w+)"); |
|
148 string tmpline, tmpaddr; |
|
149 boost::cmatch what; |
|
150 while(getline(logfd, tmpline)) |
|
151 { |
|
152 TPlacedEntry tmpEntry; |
|
153 if(regex_search(tmpline, what, endFlag)) |
|
154 { |
|
155 break; |
|
156 } |
|
157 if(regex_search(tmpline, what, sourceFile)) |
|
158 { |
|
159 tmpEntry.iFileName.assign(what[1].first, what[1].second-what[1].first); |
|
160 tmpaddr.assign(what[2].first, what[2].second-what[2].first); |
|
161 tmpEntry.iDataAddress = strtol(tmpaddr.c_str(), NULL, 16); |
|
162 symgen->AddEntry(tmpEntry); |
|
163 } |
|
164 else if(regex_search(tmpline, what, executableFile)) |
|
165 { |
|
166 tmpEntry.iFileName.assign(what[1].first, what[1].second-what[1].first); |
|
167 while(getline(logfd, tmpline) && tmpline != "") |
|
168 { |
|
169 if(regex_search(tmpline, what, codeStart)) |
|
170 { |
|
171 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
172 tmpEntry.iCodeAddress = strtol(tmpaddr.c_str(), NULL, 16); |
|
173 } |
|
174 else if(regex_search(tmpline, what, dataStart)) |
|
175 { |
|
176 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
177 tmpEntry.iDataAddress = strtol(tmpaddr.c_str(), NULL, 16); |
|
178 } |
|
179 else if(regex_search(tmpline, what, dataBssStart)) |
|
180 { |
|
181 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
182 tmpEntry.iDataBssLinearBase = strtol(tmpaddr.c_str(), NULL, 16); |
|
183 } |
|
184 else if(regex_search(tmpline, what, textSize)) |
|
185 { |
|
186 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
187 tmpEntry.iTextSize = strtol(tmpaddr.c_str(), NULL, 16); |
|
188 } |
|
189 else if(regex_search(tmpline, what, dataSize)) |
|
190 { |
|
191 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
192 tmpEntry.iDataSize = strtol(tmpaddr.c_str(), NULL, 16); |
|
193 } |
|
194 else if(regex_search(tmpline, what, bssSize)) |
|
195 { |
|
196 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
197 tmpEntry.iBssSize = strtol(tmpaddr.c_str(), NULL, 16); |
|
198 } |
|
199 else if(regex_search(tmpline, what, totalDataSize)) |
|
200 { |
|
201 tmpaddr.assign(what[1].first, what[1].second-what[1].first); |
|
202 tmpEntry.iTotalDataSize = strtol(tmpaddr.c_str(), NULL, 16); |
|
203 } |
|
204 } |
|
205 symgen->AddEntry(tmpEntry); |
|
206 } |
|
207 |
|
208 |
|
209 } |
|
210 symgen->SetFinished(); |
|
211 symgen->Release(); |
|
212 } |
|
213 else |
|
214 { |
|
215 throw LoggingException(LoggingException::INVALID_LOG_FILENAME); |
|
216 } |
|
217 } |
|
218 |