Update contrib.
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #else //!__MSVCDOTNET__
23 #endif //__MSVCDOTNET__
26 unsigned ParseHex(const char* aText, int aLength)
29 const char* end = aText + aLength;
32 unsigned c = *aText++ - '0';
35 value = (value << 4) + c;
36 } while (aText < end);
44 SymbolFile::SymbolFile(const char* aSymbolFile, bool aRofs)
45 :iText(0), iTextLower(0)
49 file.open(aSymbolFile, ios::binary);
50 #else //!__MSVCDOTNET__
51 file.open(aSymbolFile, ios::nocreate | ios::binary);
52 #endif //__MSVCDOTNET__
55 cerr << "Unable to open ROM symbol file '" << aSymbolFile << '\'' << endl;
59 file.seekg(0, ios::end);
60 iLength = file.tellg();
62 iText = new char[iLength+1];
63 file.seekg(0, ios::beg);
64 file.read(iText, iLength);
65 iText[iLength] = '\0';
71 iTextLower = new char[iLength+1];
72 for(char *p = iTextLower, *c = iText, *end = iText + iLength;c < end;c++, p++)
77 SymbolFile::~SymbolFile()
84 bool SymbolFile::Parse(SymbolFile::Parser& aParser, const char* aModuleName, PC aAddress, PC aModuleLength, int aModuleId) const
87 PC first_pc_limit = 0, last_pc_limit = 0;
88 TState state = EPreFile;
91 const char *prevName = 0;
94 if (aModuleName) // should parse only one module
96 bool not_found = false;
97 char * name = strstr(iTextLower, aModuleName);
100 for(char * p = name; p != iTextLower && *p != '\n';p--);
101 if (*p == '\n' || p == iTextLower)
104 text = iText + (name - iTextLower);
120 const char* end = iText + iLength;
121 while (text < end && state != EError)
123 char* endl = strchr(text, '\r');
133 char* p = text + strlen(text);
152 if (strncmp(text, "From", 4) != 0)
157 char* name = strrchr(text, '\\');
182 PC pc = ParseHex(text, 8);
183 pc &= ~1; // should be odd address, error in symbol table
190 char* codeType = strrchr(text+20, '(');
192 if ( codeType == NULL || (strcmp(codeType,"(.data)") != 0 &&
193 strcmp(codeType,"(.bss)") != 0 &&
194 strcmp(codeType,"(.init_array)") != 0 &&
195 strcmp(codeType,"(linker$$defined$$symbols)") != 0 &&
196 strcmp(codeType,"(ExportTable)") != 0) )
198 if(inSyms && (pc > (lastPC + lastLen)))
200 memcpy((void *)(prevName - 15), "<static> after ", 15);
201 aParser.Symbol(prevName - 15, lastPC + lastLen, pc - (lastPC + lastLen));
204 int length = ParseHex(text + 12, 4);
206 if(pc >= lastPC + lastLen)
208 bool is_added = aParser.Symbol(text + 20, pc, length);
209 if (is_added && aModuleName && !first_pc_limit)
211 first_pc_limit = pc + length;
212 last_pc_limit = pc + aModuleLength;
216 prevName = text + 20;
217 if(pc + length > lastPC + lastLen)
232 Analyse::Abort("Bad ROM symbol file format");
235 if(aModuleName && lastPC == first_pc_limit && (lastPC + lastLen) < last_pc_limit)
237 memcpy((void *)(prevName - 10), "<anon> in ", 10);
238 aParser.Symbol(prevName - 10, lastPC + lastLen, last_pc_limit - (lastPC + lastLen));
240 aParser.Done(first_pc_limit, last_pc_limit, aModuleId);