imgtools/imglib/symbolutil/symbolprocessunit.cpp
changeset 700 c22eff170fac
parent 695 46ca13b54f56
child 712 df89378e9223
equal deleted inserted replaced
699:9ca650050cf0 700:c22eff170fac
       
     1 /*
       
     2 * Copyright (c) 2010 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 #include <boost/regex.hpp>
       
    18 #include "symbolprocessunit.h"
       
    19 #include "e32image.h"
       
    20 #include "symbolgenerator.h"
       
    21 #include "h_utl.h"
       
    22 
       
    23 
       
    24 #define MAX_LINE 65535
       
    25 
       
    26 #if defined(__LINUX__)
       
    27 #define PATH_SEPARATOR '/'
       
    28 #else
       
    29 #define PATH_SEPARATOR '\\'
       
    30 #endif
       
    31 
       
    32 void SymbolProcessUnit::ProcessEntry(const TPlacedEntry& aEntry)
       
    33 {
       
    34 	if(aEntry.iFileName == "")
       
    35 		return;
       
    36 	else if(aEntry.iExecutable)
       
    37 		ProcessExecutableFile(aEntry.iFileName);
       
    38 	else
       
    39 		ProcessDataFile(aEntry.iFileName);
       
    40 }
       
    41 // CommenRomSymbolProcessUnit start
       
    42 void CommenRomSymbolProcessUnit::FlushStdOut(ostream& aOut)
       
    43 {
       
    44 	for(int i = 0; i < (int) iStdoutLog.size(); i++)
       
    45 	{
       
    46 		aOut << iStdoutLog[i];
       
    47 	}
       
    48 }
       
    49 
       
    50 void CommenRomSymbolProcessUnit::FlushSymbolContent(ostream &aOut)
       
    51 {
       
    52 	for(int i = 0; i < (int) iSymbolContentLog.size(); i++)
       
    53 	{
       
    54 		aOut << iSymbolContentLog[i];
       
    55 	}
       
    56 }
       
    57 
       
    58 void CommenRomSymbolProcessUnit::ResetContentLog()
       
    59 {
       
    60 	iStdoutLog.clear();
       
    61 	iSymbolContentLog.clear();
       
    62 }
       
    63 
       
    64 void CommenRomSymbolProcessUnit::ProcessEntry(const TPlacedEntry& aEntry)
       
    65 {
       
    66 	iPlacedEntry = aEntry;
       
    67 	SymbolProcessUnit::ProcessEntry(aEntry);
       
    68 }
       
    69 
       
    70 void CommenRomSymbolProcessUnit::ProcessExecutableFile(const string& aFile)
       
    71 {
       
    72 	ResetContentLog();
       
    73 	char str[MAX_LINE];
       
    74 	string outString;
       
    75 	outString = "\nFrom    ";
       
    76 	outString += aFile + "\n\n";
       
    77 	iSymbolContentLog.push_back(outString);
       
    78 	string mapFile2 = aFile+".map";
       
    79 	size_t dot = aFile.rfind('.');
       
    80 	string mapFile = aFile.substr(0,dot)+".map";
       
    81 	ifstream fMap;
       
    82 	fMap.open(mapFile2.c_str());
       
    83 	if(!fMap.is_open()) {
       
    84 		fMap.open(mapFile.c_str());
       
    85 	}
       
    86 
       
    87 	if(!fMap.is_open()) {
       
    88 		sprintf(str, "\nWarning: Can't open \"%s\" or \"%s\"\n",mapFile2.c_str(),mapFile.c_str());
       
    89 		iStdoutLog.push_back(str);
       
    90 	    memset(str,0,sizeof(str));
       
    91 	    sprintf(str, "%08x    %04x    ", (unsigned int)iPlacedEntry.iCodeAddress, (unsigned int)iPlacedEntry.iTotalSize);
       
    92 	    outString = str;
       
    93 	    outString += aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
       
    94 	    iSymbolContentLog.push_back(outString);
       
    95 	}
       
    96 	else {
       
    97 	    if(!fMap.good()) fMap.clear();
       
    98 	    char buffer[100];
       
    99 	    fMap.getline(buffer, 100);
       
   100 	    boost::regex regARMV5("ARM Linker", boost::regex::icase);
       
   101 	    boost::regex regGCCEoARMV4("Archive member included", boost::regex::icase);
       
   102 	    boost::cmatch what;
       
   103 	    if(regex_search(buffer, what, regARMV5)) {
       
   104 	        ProcessArmv5File(aFile, fMap);
       
   105 	    }
       
   106 	    else if(regex_search(buffer, what, regGCCEoARMV4)) {
       
   107 	        ProcessGcceOrArm4File(aFile, fMap);
       
   108 	    }
       
   109 	    else {
       
   110 		fMap.seekg(0, ios_base::beg);
       
   111 		ProcessX86File(aFile, fMap);
       
   112 	    }
       
   113 	}
       
   114 }
       
   115 
       
   116 void CommenRomSymbolProcessUnit::ProcessDataFile(const string& aFile)
       
   117 {
       
   118 	ResetContentLog();
       
   119 	char str[MAX_LINE];
       
   120 	memset(str,0,sizeof(str));
       
   121 	string basename = aFile.substr(aFile.rfind(PATH_SEPARATOR)+1);
       
   122 	sprintf(str, "\nFrom    %s\n\n%08x    0000    %s\n", aFile.c_str(), (unsigned int) iPlacedEntry.iDataAddress, basename.c_str());
       
   123 	iSymbolContentLog.push_back(str);
       
   124 }
       
   125 
       
   126 struct ArmSymbolInfo {
       
   127 	string name ;
       
   128 	TUint size ;
       
   129 	string section ;
       
   130 };
       
   131 typedef multimap<TUint32,ArmSymbolInfo> ArmSymMap ;
       
   132 
       
   133 #define SKIP_WS(p)	 while((*p) == ' ' ||  (*p) == '\t') (p)++ 
       
   134 #define FIND_WS(p)	 while((*p) != ' ' &&  (*p) != '\t' && (*p) != 0) (p)++ 
       
   135 static void split(char* str, vector<char*>& result) {
       
   136 	result.clear();
       
   137 	while(*str) {
       
   138 		SKIP_WS(str);
       
   139 		char* saved = str ; 
       
   140 		FIND_WS(str);
       
   141 		bool end = (0 == *str);
       
   142 		*str = 0 ; 
       
   143 		if(saved != str)
       
   144 			result.push_back(saved);		
       
   145 		if(!end) str ++ ; 
       
   146 	}	 
       
   147 }
       
   148 static void make_lower(char* str){
       
   149 	while(*str){
       
   150 		if(*str >= 'A' && *str >= 'Z') {
       
   151 			*str += ('a' - 'A');
       
   152 		}
       
   153 		str++;
       
   154 	}
       
   155 }
       
   156 
       
   157 void CommenRomSymbolProcessUnit::ProcessArmv5File(const string& aFile, ifstream& aMap)
       
   158 {
       
   159 	string symName ; 
       
   160 	ArmSymMap symbols ; 
       
   161 	vector<char*> words ;
       
   162 	ArmSymbolInfo info;
       
   163 	char* lineStart ;
       
   164 	char buffer[MAX_LINE];  
       
   165 	while(aMap.good() && (!aMap.eof())){
       
   166 		*buffer = 0;
       
   167 		aMap.getline(buffer,MAX_LINE);
       
   168 		lineStart = buffer ;
       
   169 		SKIP_WS(lineStart);	 
       
   170 		if(strstr(lineStart,"Global Symbols"))
       
   171 			break ;
       
   172 		char* armstamp = strstr(lineStart,"ARM Code");
       
   173 		if(0 == armstamp)
       
   174 			armstamp = strstr(lineStart,"Thumb Code") ;
       
   175 		if(0 == armstamp) continue ; 
       
   176 		*(armstamp - 1) = 0 ;
       
   177 		
       
   178 		char* hexStr = lineStart ;
       
   179 		char* nameEnd;
       
   180 		while(1) {
       
   181 			hexStr = strstr(hexStr,"0x");
       
   182 			if(0 == hexStr) break ; 		
       
   183 			nameEnd = hexStr - 1;
       
   184 			if(*nameEnd == ' ' || *nameEnd == '\t') break ;
       
   185 			hexStr += 2 ;
       
   186 		}	 
       
   187 		if(0 == hexStr) continue ; 	
       
   188 		while(nameEnd > lineStart && (*nameEnd == ' ' || *nameEnd == '\t'))
       
   189 			nameEnd -- ;
       
   190 		
       
   191 		nameEnd[1] = 0;
       
   192 		info.name = lineStart;		
       
   193 		char* temp ;
       
   194 		TUint32 addr = strtoul(hexStr + 2,&temp,16);
       
   195 		char* decStr ;
       
   196 		if(*armstamp == 'A')
       
   197 			decStr = armstamp + 9 ;
       
   198 		else 
       
   199 			decStr = armstamp + 11 ;
       
   200 		SKIP_WS(decStr);
       
   201 		info.size = strtoul(decStr,&temp,10);
       
   202 		SKIP_WS(temp);
       
   203 		info.section = temp;
       
   204 		if(info.section.find("(StubCode)") != string::npos )
       
   205 			info.size = 8 ; 			
       
   206 		if(addr > 0){
       
   207 			symbols.insert(pair<TUint32,ArmSymbolInfo>(addr,info));
       
   208 		}
       
   209 	}	 
       
   210 	size_t lenOfFileName = iPlacedEntry.iFileName.length();
       
   211 	while(aMap.good() && (!aMap.eof())){
       
   212 		*buffer = 0;
       
   213 		aMap.getline(buffer,MAX_LINE);
       
   214 		lineStart = buffer ;
       
   215 		SKIP_WS(lineStart); 
       
   216 		char* hexStr = lineStart ;
       
   217 		char* nameEnd;
       
   218 		while(1) {
       
   219 			hexStr = strstr(hexStr,"0x");
       
   220 			if(0 == hexStr) break ; 		
       
   221 			nameEnd = hexStr - 1;
       
   222 			if(*nameEnd == ' ' || *nameEnd == '\t') 
       
   223 				break ;
       
   224 			hexStr += 2 ;
       
   225 		}	 
       
   226 		if(0 == hexStr) continue ; 
       
   227 		while(nameEnd > lineStart && (*nameEnd == ' ' || *nameEnd == '\t')){
       
   228 			nameEnd -- ;
       
   229 		}
       
   230 		nameEnd[1] = 0;
       
   231 		info.name = lineStart; 
       
   232 		char *temp ;
       
   233 		TUint32 addr = strtoul(hexStr + 2,&temp,16);
       
   234 		while(*temp < '0' || *temp > '9' )//[^\d]*
       
   235 			temp++ ;
       
   236 		char* decStr = temp ;
       
   237 		info.size = strtoul(decStr,&temp,10);
       
   238 		SKIP_WS(temp);
       
   239 		info.section = temp;
       
   240 		if(info.section.find("(StubCode)") != string::npos )
       
   241 			info.size = 8 ; 
       
   242 		if(addr > 0){
       
   243 			symbols.insert(pair<TUint32,ArmSymbolInfo>(addr,info));
       
   244 		} 
       
   245 	}
       
   246 	
       
   247 	TUint32 textSectAddr = 0x00008000;  // .text gets linked at 0x00008000
       
   248 	TUint32 dataSectAddr = 0x00400000 ; // .data gets linked at 0x00400000
       
   249 	vector<pair<int,char*> > lines ;	
       
   250 	size_t allocBytes;
       
   251 	for( ArmSymMap::iterator it = symbols.begin(); it != symbols.end() ; it++){
       
   252 		TUint32 thisAddr = it->first ;
       
   253 		TUint32 romAddr ;
       
   254 		ArmSymbolInfo& info = it->second; 
       
   255 		if (thisAddr >= textSectAddr && thisAddr <= (textSectAddr + iPlacedEntry.iTextSize)) {
       
   256 				romAddr = thisAddr - textSectAddr + iPlacedEntry.iCodeAddress ;
       
   257 		} 
       
   258 		else if ( iPlacedEntry.iDataAddress && 
       
   259 			( thisAddr >= dataSectAddr && thisAddr <= (dataSectAddr + iPlacedEntry.iTextSize))) {
       
   260 			romAddr = thisAddr-dataSectAddr + iPlacedEntry.iDataBssLinearBase;
       
   261 		} 
       
   262 		else if ( iPlacedEntry.iDataBssLinearBase && 
       
   263 			( thisAddr >= dataSectAddr && thisAddr <= (dataSectAddr+ iPlacedEntry.iTotalDataSize))) {
       
   264 			romAddr = thisAddr - dataSectAddr + iPlacedEntry.iDataBssLinearBase;
       
   265 		} 
       
   266 		else { 
       
   267 			allocBytes = info.name.length() + 60;
       
   268 			char* msg = new char[allocBytes] ;
       
   269 			snprintf(msg,allocBytes,"\r\nWarning: Symbol %s @ 0x%08x not in text or data segments\r\n", \
       
   270 				info.name.c_str() ,(unsigned int)thisAddr) ; 
       
   271 			iStdoutLog.push_back(msg);	
       
   272 			allocBytes = lenOfFileName + 80;
       
   273 			msg = new char[allocBytes];
       
   274 			snprintf(msg,allocBytes,"Warning:  The map file for binary %s is out-of-sync with the binary itself\r\n\r\n",iPlacedEntry.iFileName.c_str());
       
   275 			iStdoutLog.push_back(msg);	
       
   276 			continue ;
       
   277 		}
       
   278 		allocBytes =  info.section.length() + info.name.length() + 140;
       
   279 		char* outputLine = new char[allocBytes];
       
   280 		int len = snprintf(outputLine,allocBytes,"%08x    %04x    %-40s  %s\r\n",(unsigned int)romAddr,info.size,
       
   281 			info.name.c_str(),info.section.c_str()); 
       
   282 		if((size_t)len > allocBytes) {
       
   283 			allocBytes = len + 4 ;
       
   284 			delete []outputLine;
       
   285 			outputLine = new char[allocBytes];
       
   286 			len = snprintf(outputLine,allocBytes,"%08x    %04x    %-40s  %s\r\n",(unsigned int)romAddr,info.size,
       
   287 			info.name.c_str(),info.section.c_str()); 
       
   288 		}
       
   289 		lines.push_back(pair<int,char*>(len,outputLine));
       
   290 	 
       
   291 	} 
       
   292 
       
   293 	for (vector<pair<int,char*> >::iterator i = lines.begin() ; i < lines.end(); i ++ ) {
       
   294 		char* line = i->second; 
       
   295 		iSymbolContentLog.push_back(line);
       
   296 		delete[] line;
       
   297 	}
       
   298 }
       
   299 
       
   300 template<typename M, typename K,typename V> 
       
   301 static void put_to_map(M& m,const K& k, const V& v) {
       
   302 	typedef typename M::iterator iterator;
       
   303 	iterator it = m.find(k);
       
   304 	if(m.end() == it){
       
   305 		m.insert(pair<K,V>(k,v));
       
   306 	}
       
   307 	else { 
       
   308 		it->second = v ;
       
   309 	}	
       
   310 }
       
   311 
       
   312 void CommenRomSymbolProcessUnit::ProcessGcceOrArm4File(const string& aFile, ifstream& aMap)
       
   313 {
       
   314 	char* lineStart; 
       
   315 	vector<char*> words ;
       
   316 	char buffer[MAX_LINE];
       
   317 	while(aMap.good() && (!aMap.eof())){
       
   318 		aMap.getline(buffer,MAX_LINE);
       
   319 		lineStart = buffer ;
       
   320 		SKIP_WS(lineStart);
       
   321 		if( 0 == strncmp(lineStart,".text",5)) {
       
   322 			lineStart += 5;
       
   323 			break ;
       
   324 		}		
       
   325 	}
       
   326 	split(lineStart,words);
       
   327 	TUint32 codeAddr , codeSize;
       
   328 	size_t allocBytes ;
       
   329 	if(words.size() != 2 ||
       
   330 	KErrNone != Val(codeAddr,words.at(0)) || 
       
   331 	KErrNone != Val(codeSize,words.at(1))) {
       
   332 		allocBytes = iPlacedEntry.iFileName.length() + 60;
       
   333 		char* msg = new char[allocBytes];
       
   334 		snprintf(msg,allocBytes,"\nError: Can't get .text section info for \"%s\"\r\n",iPlacedEntry.iFileName.c_str());
       
   335 		iStdoutLog.push_back(msg);
       
   336 		return;
       
   337 	}
       
   338 	map<TUint32,string> symbols ;
       
   339 	TUint32 stubHex = 0;
       
   340 	//Slurp symbols 'til the end of the text section
       
   341 	while(aMap.good() && (!aMap.eof())){
       
   342 		aMap.getline(buffer,MAX_LINE);
       
   343 		lineStart = buffer ;
       
   344 		SKIP_WS(lineStart); 
       
   345 		if(0 == *lineStart) break ; //blank line marks the end of the text section
       
   346 		
       
   347 		// .text <addr> <len>  <library(member)>
       
   348 		// .text$something
       
   349 		//       <addr> <len>  <library(member)>
       
   350 		//       <addr> <len>  LONG 0x0
       
   351 		// (/^\s(\.text)?\s+(0x\w+)\s+(0x\w+)\s+(.*)$/io)	 
       
   352 		if(strncmp(lineStart,".text",5) == 0){
       
   353 			lineStart += 5 ;
       
   354 			SKIP_WS(lineStart);
       
   355 		}
       
   356 		char* hex1 = NULL ;
       
   357 		char* hex2 = NULL ;
       
   358 		char* strAfterhex1 = NULL ;
       
   359 		TUint32 addr,size ;
       
   360 		if(strncmp(lineStart,"0x",2) == 0){
       
   361 			hex1 = lineStart + 2;
       
   362 			char* temp ;
       
   363 			addr = strtoul(hex1,&temp,16);
       
   364 			SKIP_WS(temp);
       
   365 			strAfterhex1 = temp ;
       
   366 			if(strncmp(temp,"0x",2) == 0){
       
   367 				hex2 = temp + 2 ;
       
   368 			}
       
   369 		}
       
   370 		if(NULL != hex2){
       
   371 			char* libraryfile ;
       
   372 			size = strtoul(hex2,&libraryfile,16);
       
   373 			SKIP_WS(libraryfile);  
       
   374 			TUint32 key = addr + size ;
       
   375 			put_to_map(symbols,key,string(""));//impossible symbol as end marker 
       
   376 			make_lower(libraryfile); 
       
   377 			// EUSER.LIB(ds01423.o)
       
   378 			// EUSER.LIB(C:/TEMP/d1000s_01423.o)
       
   379 			size_t len = strlen(libraryfile);
       
   380 			char* p1 = strstr(libraryfile,".lib(");
       
   381 			if(NULL == p1) 
       
   382 				continue ; 
       
   383 			p1 += 5;
       
   384 			if(strcmp(libraryfile + len - 3,".o)")!= 0)
       
   385 				continue ;		 
       
   386 			len -= 3 ;
       
   387 			libraryfile[len] = 0; 
       
   388 			if(EFalse == IsValidNumber(libraryfile + len - 5))
       
   389 				continue ;
       
   390 			len -= 7 ;
       
   391 			if('_' == libraryfile[len])
       
   392 				len -- ;
       
   393 			if('s' != libraryfile[len])
       
   394 				continue ;		 
       
   395 			char* p2 = libraryfile + len - 1;
       
   396 			while(p2 > p1 ) { 
       
   397 				if(*p2 < '0' || *p2 > '9')
       
   398 					break ;
       
   399 				p2 -- ;
       
   400 			}
       
   401 			if(*p2 != 'd') 
       
   402 				continue ;
       
   403 			stubHex = addr ;
       
   404 		}
       
   405 		else if(NULL != hex1 && NULL != strAfterhex1){ 
       
   406 			//#  <addr>  <symbol name possibly including spaces>
       
   407 			//(/^\s+(\w+)\s\s+([a-zA-Z_].+)/o) 			 
       
   408 			char* symName = strAfterhex1; 
       
   409 			if((*symName >= 'A' && *symName <= 'Z') ||
       
   410 				(*symName >= 'a' && *symName <= 'z') || *symName == '_') {				 
       
   411 				string symbol(symName);
       
   412 				if(addr == stubHex) 
       
   413 					symbol.insert(0,"stub ");
       
   414 			 
       
   415 				put_to_map(symbols,addr,symbol);
       
   416 				 
       
   417 			}			
       
   418 		}		
       
   419 	}  
       
   420 	map<TUint32,string>::iterator it = symbols.begin();
       
   421 	TUint32 lastAddr = it->first;
       
   422 	string lastSymName = it->second;
       
   423 	vector<pair<int,char*> >lines ;
       
   424 	it ++ ;
       
   425 	while(it != symbols.end()) {		
       
   426 		TUint32 addr = it->first ; 
       
   427 		unsigned int fixedupAddr = lastAddr - codeAddr + iPlacedEntry.iCodeAddress;
       
   428 		TUint size = addr - lastAddr ;
       
   429 		if(!lastSymName.empty()) {
       
   430 			allocBytes = lastSymName.length() + 40;
       
   431 			char* outputLine = new char[allocBytes];
       
   432 			int n = snprintf(outputLine,allocBytes,"%08x    %04x    %s\r\n", fixedupAddr,size,lastSymName.c_str()); 
       
   433 			lines.push_back(pair<int,char*>(n,outputLine));
       
   434 		}		
       
   435 		lastAddr = addr ;
       
   436 		lastSymName = it->second;
       
   437 		it ++ ;
       
   438 	}
       
   439 	
       
   440 	vector<pair<int,char*> >::iterator i; 
       
   441 	for ( i = lines.begin() ; i < lines.end(); i ++ ) {
       
   442 		char* line = i->second ;
       
   443 		iSymbolContentLog.push_back(line);
       
   444 		delete []line ;
       
   445 	}
       
   446 }
       
   447 
       
   448 void CommenRomSymbolProcessUnit::ProcessX86File(const string& aFile, ifstream& aMap)
       
   449 {
       
   450 	char buffer[MAX_LINE]; 
       
   451 	char* lineStart; 
       
   452 	while(aMap.good() && (!aMap.eof())){
       
   453 		aMap.getline(buffer,MAX_LINE);
       
   454 		lineStart = buffer ;
       
   455 		SKIP_WS(lineStart);
       
   456 		if( 0 == strncmp(lineStart,"Address",7)) { 
       
   457 			break ;
       
   458 		}		
       
   459 	}
       
   460 	aMap.getline(buffer,MAX_LINE);
       
   461 	string lastName ;
       
   462 	TUint32 lastAddr = 0;
       
   463 	size_t allocBytes ;
       
   464 	vector<pair<int, char*> >lines ;
       
   465 	while(aMap.good() && (!aMap.eof())){
       
   466 		aMap.getline(buffer,MAX_LINE);
       
   467 		lineStart = buffer ;
       
   468 		SKIP_WS(lineStart);
       
   469 		if(0 != strncmp(lineStart,"0001:",5))
       
   470 			break ;		 
       
   471 		char* end ; 
       
   472 		TUint32 addr = strtoul(lineStart + 5,&end,16);
       
   473 		char* name = end + 1;
       
   474 		SKIP_WS(name);
       
   475 		end = name + 1;
       
   476 		FIND_WS(end);
       
   477 		*end = 0 ;
       
   478 		if(!lastName.empty()){
       
   479 			unsigned int size = addr - lastAddr ; 
       
   480 			unsigned int romAddr = lastAddr + iPlacedEntry.iCodeAddress;
       
   481 			allocBytes = lastName.length() + 40;
       
   482 			char* outputLine = new char[allocBytes];
       
   483 			int n = snprintf(outputLine,allocBytes,"%08x    %04x    %s\r\n",romAddr,size,lastName.c_str());
       
   484 			lines.push_back(pair<int, char*>(n,outputLine));
       
   485 		}		
       
   486 	}
       
   487 
       
   488 	vector<pair<int,char*> >::iterator it; 
       
   489 	for ( it = lines.begin() ; it < lines.end(); it ++ ) {
       
   490 		char* line = it->second  ;
       
   491 		iSymbolContentLog.push_back(line);
       
   492 		delete []line ;
       
   493 	}	
       
   494 	if(!lastName.empty()){
       
   495 		allocBytes = lastName.length() + 40 ;
       
   496 		char* outputLine = new char[allocBytes];
       
   497 		unsigned int romAddr = lastAddr + iPlacedEntry.iCodeAddress;
       
   498 		snprintf(outputLine,allocBytes,"%08x    0000    %s\r\n",romAddr,lastName.c_str());
       
   499 		iSymbolContentLog.push_back(outputLine);
       
   500 		delete []outputLine ;
       
   501 	}
       
   502 }
       
   503 // CommenRomSymbolProcessUnit end
       
   504 // CommenRofsSymbolProcessUnit start 
       
   505 void CommenRofsSymbolProcessUnit::ProcessExecutableFile(const string& aFile)
       
   506 {
       
   507 	ResetContentLog();
       
   508 	char str[MAX_LINE];
       
   509 	string outString;
       
   510 	outString = "\nFrom    ";
       
   511 	outString += aFile + "\n\n";
       
   512 	iSymbolContentLog.push_back(outString);
       
   513 	string mapFile2 = aFile+".map";
       
   514 	size_t dot = aFile.rfind('.');
       
   515 	string mapFile = aFile.substr(0,dot)+".map";
       
   516 	ifstream fMap;
       
   517 	fMap.open(mapFile2.c_str());
       
   518 	if(!fMap.is_open()) {
       
   519 		fMap.open(mapFile.c_str());
       
   520 	}
       
   521 
       
   522 	if(!fMap.is_open()) {
       
   523 		sprintf(str, "%s\nWarning: Can't open \"%s\" or \"%s\"\n",aFile.c_str(),mapFile2.c_str(),mapFile.c_str());
       
   524 		iStdoutLog.push_back(str);
       
   525 	    int binSize = GetSizeFromBinFile(aFile);
       
   526 	    memset(str,0,sizeof(str));
       
   527 	    sprintf(str,"%04x", binSize);
       
   528 	    outString = "00000000    ";
       
   529 	    outString += str;
       
   530 	    outString += "    ";
       
   531 	    outString += aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
       
   532 	    iSymbolContentLog.push_back(outString);
       
   533 	}
       
   534 	else {
       
   535 		if(!fMap.good()) fMap.clear();
       
   536 	    boost::regex regARMV5("ARMV5", boost::regex::icase);
       
   537 	    boost::regex regGCCEoARMV4("(GCCE|ARMV4)", boost::regex::icase);
       
   538 	    boost::cmatch what;
       
   539 	    if(regex_search(aFile, what, regARMV5)) {
       
   540 	        ProcessArmv5File(aFile, fMap);
       
   541 	    }
       
   542 	    else if(regex_search(aFile, what, regGCCEoARMV4)) {
       
   543 	        ProcessGcceOrArm4File(aFile, fMap);
       
   544 	    }
       
   545 	    else {
       
   546 	        sprintf(str, "\nWarning: cannot determine linker type used to create %s\n",aFile.c_str());
       
   547 	        iStdoutLog.push_back(str);
       
   548 	        outString = "00000000    0000    ";
       
   549 	        outString += aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
       
   550 	        iSymbolContentLog.push_back(outString);
       
   551 	        }
       
   552 	    }
       
   553 }
       
   554 void CommenRofsSymbolProcessUnit::ProcessDataFile(const string& aFile)
       
   555 {
       
   556 	ResetContentLog();
       
   557 	string line = "\nFrom    "+aFile+"\n\n00000000    0000    "+aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
       
   558 	iSymbolContentLog.push_back(line);
       
   559 }
       
   560 void CommenRofsSymbolProcessUnit::FlushStdOut(ostream& aOut)
       
   561 {
       
   562 	for(int i = 0; i < (int) iStdoutLog.size(); i++)
       
   563 	{
       
   564 		aOut << iStdoutLog[i];
       
   565 	}
       
   566 }
       
   567 void CommenRofsSymbolProcessUnit::FlushSymbolContent(ostream &aOut)
       
   568 {
       
   569 	for(int i = 0; i < (int) iSymbolContentLog.size(); i++)
       
   570 	{
       
   571 		aOut << iSymbolContentLog[i];
       
   572 	}
       
   573 }
       
   574 void CommenRofsSymbolProcessUnit::ResetContentLog()
       
   575 {
       
   576 	iStdoutLog.clear();
       
   577 	iSymbolContentLog.clear();
       
   578 }
       
   579 void CommenRofsSymbolProcessUnit::ProcessArmv5File( const string& fileName, ifstream& aMap ){
       
   580     aMap.seekg (0, ios::beg);
       
   581     char str[MAX_LINE];
       
   582     char outbuffer[MAX_LINE];
       
   583     string outString;
       
   584     aMap.getline(str,MAX_LINE);
       
   585     boost::cmatch what;
       
   586     boost::regex reg("^ARM Linker");
       
   587     if(!regex_search(str, what, reg)) {
       
   588         sprintf(outbuffer, "\nWarning: expecting %s to be generated by ARM linker\n", fileName.c_str());
       
   589         iStdoutLog.push_back(outbuffer);
       
   590         outString = "00000000    0000    "+fileName.substr(fileName.rfind(PATH_SEPARATOR)+1)+"\n";
       
   591         iSymbolContentLog.push_back(outString);
       
   592     }
       
   593     reg.assign("Global Symbols");
       
   594     while(aMap.getline(str,MAX_LINE)) {
       
   595         if(regex_search(str, what, reg)) {
       
   596             break;
       
   597         }
       
   598     }
       
   599 
       
   600     reg.assign("^\\s*(.+)\\s*0x(\\S+)\\s+[^\\d]*(\\d+)\\s+(.*)$");
       
   601     string sSym,sTmp,sSection;
       
   602     unsigned int addr,size,baseOffset = 0;
       
   603     map<unsigned int,string> syms;
       
   604     char symString[MAX_LINE];
       
   605     while(aMap.getline(str,MAX_LINE)) {
       
   606         if(regex_search(str, what, reg)) {
       
   607             sSym.assign(what[1].first,what[1].second-what[1].first);
       
   608             sTmp.assign(what[2].first,what[2].second-what[2].first);
       
   609             addr = strtol(sTmp.c_str(), NULL, 16);
       
   610             sTmp.assign(what[3].first,what[3].second-what[3].first);
       
   611             size = strtol(sTmp.c_str(), NULL, 10);
       
   612             sSection.assign(what[4].first,what[4].second-what[4].first);
       
   613             if(sSection.find("(StubCode)") != string::npos)
       
   614                 size = 8;
       
   615             if(addr > 0) {
       
   616                 memset(symString,0,sizeof(symString));
       
   617                 sprintf(symString,"%04x    ",size);
       
   618                 outString = symString;
       
   619                 outString += sSym+" ";
       
   620                 outString += sSection;
       
   621                 if(baseOffset == 0)
       
   622                     baseOffset = addr;
       
   623                 unsigned int k = addr - baseOffset;
       
   624                 if( (syms.find(k) == syms.end()) || size != 0)
       
   625                     syms[k] = outString;
       
   626             }
       
   627             // end of addr>0
       
   628         }
       
   629         // end of regex_search
       
   630     }
       
   631 
       
   632     map<unsigned int,string>::iterator it;
       
   633     for(it = syms.begin(); it != syms.end(); it++) {
       
   634         memset(str,0,sizeof(str));
       
   635         sprintf(str,"%08x",it->first);
       
   636         outString = str;
       
   637         outString += "    ";
       
   638         outString += it->second+"\n";
       
   639         iSymbolContentLog.push_back(outString);
       
   640     }
       
   641 }
       
   642 void CommenRofsSymbolProcessUnit::ProcessGcceOrArm4File( const string& fileName, ifstream& aMap ){
       
   643     aMap.seekg (0, ios_base::beg);
       
   644     char str[MAX_LINE];
       
   645     char outbuffer[MAX_LINE];
       
   646     aMap.getline(str,MAX_LINE);
       
   647     boost::cmatch what;
       
   648     boost::regex reg("^\\.text\\s+");
       
   649     while(aMap.getline(str,MAX_LINE)) {
       
   650         if(regex_search(str, what, reg)) {
       
   651             break;
       
   652         }
       
   653     }
       
   654 
       
   655     reg.assign("^\\.text\\s+(\\w+)\\s+\\w+");
       
   656     if(!regex_search(str, what, reg)) {
       
   657         sprintf(outbuffer, "ERROR: Can't get .text section info for \"%s\"\n",fileName.c_str());
       
   658         iStdoutLog.push_back(outbuffer);
       
   659     }
       
   660     else {
       
   661         string sTmp, sLibFile;
       
   662         sTmp.assign(what[1].first,what[1].second-what[1].first);
       
   663         unsigned int imgText = strtol(sTmp.c_str(), NULL, 16);
       
   664 
       
   665         reg.assign("^LONG 0x.*", boost::regex::icase);
       
   666         boost::cmatch what1;
       
   667         boost::regex reg1("^\\s(\\.text)?\\s+(0x\\w+)\\s+(0x\\w+)\\s+(.*)$", boost::regex::icase);
       
   668         boost::regex reg2("^\\s+(\\w+)\\s\\s+([a-zA-Z_].+)", boost::regex::icase);
       
   669         boost::regex reg3(".*lib\\(.*d\\d*s_?\\d{5}.o\\)$", boost::regex::icase);
       
   670 
       
   671         map<unsigned int,string> syms;
       
   672         unsigned int addr, len, stubhex;
       
   673 
       
   674         while(aMap.getline(str,MAX_LINE)) {
       
   675             if(strlen(str) == 0)
       
   676                 break;
       
   677             else if(regex_search(str, what, reg1)) {
       
   678                 sLibFile.assign(what[4].first,what[4].second-what[4].first);
       
   679                 if(!regex_search(sLibFile, what1, reg)) {
       
   680                     sTmp.assign(what[2].first,what[2].second-what[2].first);
       
   681                     addr = strtol(sTmp.c_str(), NULL, 16);
       
   682                     sTmp.assign(what[3].first,what[3].second-what[3].first);
       
   683                     len = strtol(sTmp.c_str(), NULL, 16);
       
   684                     syms[addr+len] = "";
       
   685                     if(regex_search(sLibFile, what, reg3)) {
       
   686                         stubhex = addr;
       
   687                     }
       
   688                 }
       
   689             }
       
   690             else if(regex_search(str, what, reg2)) {
       
   691                 sTmp.assign(what[1].first,what[1].second-what[1].first);
       
   692                 addr = strtol(sTmp.c_str(), NULL, 16);
       
   693                 sTmp.assign(what[2].first,what[2].second-what[2].first);
       
   694                 syms[addr] = (addr == stubhex)? ("stub "+sTmp) : sTmp;
       
   695             }
       
   696         }
       
   697 
       
   698         map<unsigned int,string>::iterator it = syms.begin();
       
   699         map<unsigned int,string>::iterator itp = it++;
       
   700         string outString;
       
   701         for(; it != syms.end(); itp = it++) {
       
   702             if(itp->second != "") {
       
   703                 memset(str,0,sizeof(str));
       
   704                 sprintf(str,"%08x    %04x    ",(itp->first-imgText), (it->first-itp->first));
       
   705                 outString = str;
       
   706                 outString += it->second+"\n";
       
   707                 iSymbolContentLog.push_back(outString);
       
   708             }
       
   709         }
       
   710     }
       
   711 }
       
   712 // CommenRofsSymbolProcessUnit end
       
   713 int SymbolProcessUnit::GetSizeFromBinFile( const string& fileName ){
       
   714     TInt ret = 0;
       
   715     //char outbuffer[MAX_LINE];
       
   716     ifstream aIf(fileName.c_str(), ios_base::binary);
       
   717     if( !aIf.is_open() ) {
       
   718         printf("Warning: Cannot open file %s\n", fileName.c_str());
       
   719         //iStdoutLog.push_back(outbuffer);
       
   720     }
       
   721     else {
       
   722         E32ImageFile e32Image;
       
   723         TUint32 aSz;
       
   724 
       
   725         aIf.seekg(0,ios_base::end);
       
   726         aSz = aIf.tellg();
       
   727 
       
   728         e32Image.Adjust(aSz);
       
   729         e32Image.iFileSize = aSz;
       
   730 
       
   731         aIf.seekg(0,ios_base::beg);
       
   732         aIf >> e32Image;
       
   733         ret = e32Image.iOrigHdr->iCodeSize;
       
   734     }
       
   735     return ret;
       
   736 }
       
   737 
       
   738 // for BSym
       
   739 void BsymRofsSymbolProcessUnit::ProcessEntry(const TPlacedEntry& aEntry)
       
   740 {
       
   741 	SymbolProcessUnit::ProcessEntry(aEntry);
       
   742 	if(aEntry.iFileName == "")
       
   743 		return;
       
   744 	else if(aEntry.iExecutable)
       
   745 		ProcessExecutableFile(aEntry.iFileName);
       
   746 	else
       
   747 		ProcessDataFile(aEntry.iFileName);
       
   748 	iMapFileInfo.iDbgUnitPCEntry.iPCName = aEntry.iFileName;
       
   749 	iMapFileInfo.iDbgUnitPCEntry.iDevName = aEntry.iDevFileName;
       
   750 }
       
   751 
       
   752 void BsymRofsSymbolProcessUnit::ProcessExecutableFile(const string& aFile)
       
   753 {
       
   754 	ResetContentLog();
       
   755 	char str[MAX_LINE];
       
   756 	string mapFile2 = aFile+".map";
       
   757 	size_t dot = aFile.rfind('.');
       
   758 	string mapFile = aFile.substr(0,dot)+".map";
       
   759 	ifstream fMap;
       
   760 	fMap.open(mapFile2.c_str());
       
   761 	if(!fMap.is_open()) {
       
   762 		fMap.open(mapFile.c_str());
       
   763 	}
       
   764 
       
   765 	if(!fMap.is_open()) {
       
   766 		sprintf(str, "%s\nWarning: Can't open \"%s\" or \"%s\"\n",aFile.c_str(),mapFile2.c_str(),mapFile.c_str());
       
   767 		iStdoutLog.push_back(str);
       
   768 	    int binSize = GetSizeFromBinFile(aFile);
       
   769 	    TSymbolPCEntry tmpEntry;
       
   770 	    tmpEntry.iSymbolEntry.iAddress = 0;
       
   771 	    tmpEntry.iSymbolEntry.iLength = binSize;
       
   772 	    tmpEntry.iName = aFile.substr(aFile.rfind(PATH_SEPARATOR)+1);
       
   773 	    iMapFileInfo.iSymbolPCEntrySet.push_back(tmpEntry);
       
   774 	    iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iDataSymbolCount++;
       
   775 	}
       
   776 	else {
       
   777 		if(!fMap.good()) fMap.clear();
       
   778 	    boost::regex regARMV5("ARMV5", boost::regex::icase);
       
   779 	    boost::regex regGCCEoARMV4("(GCCE|ARMV4)", boost::regex::icase);
       
   780 	    boost::cmatch what;
       
   781 	    if(regex_search(aFile, what, regARMV5)) {
       
   782 	        ProcessArmv5File(aFile, fMap);
       
   783 	    }
       
   784 	    else if(regex_search(aFile, what, regGCCEoARMV4)) {
       
   785 	        ProcessGcceOrArm4File(aFile, fMap);
       
   786 	    }
       
   787 	    else {
       
   788 	        sprintf(str, "\nWarning: cannot determine linker type used to create %s\n",aFile.c_str());
       
   789 	        iStdoutLog.push_back(str);
       
   790 	    	TSymbolPCEntry tmpEntry;
       
   791 	    	tmpEntry.iSymbolEntry.iAddress = 0;
       
   792 	    	tmpEntry.iSymbolEntry.iLength = 0;
       
   793 	    	tmpEntry.iName = aFile.substr(aFile.rfind(PATH_SEPARATOR)+1);
       
   794 	    	iMapFileInfo.iSymbolPCEntrySet.push_back(tmpEntry);
       
   795 	    	iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iDataSymbolCount++;
       
   796 	        }
       
   797 	    }
       
   798 }
       
   799 void BsymRofsSymbolProcessUnit::ProcessDataFile(const string& aFile)
       
   800 {
       
   801 	ResetContentLog();
       
   802 	TSymbolPCEntry tmpEntry;
       
   803 	tmpEntry.iSymbolEntry.iAddress = 0;
       
   804 	tmpEntry.iSymbolEntry.iLength = 0;
       
   805 	tmpEntry.iName = aFile.substr(aFile.rfind(PATH_SEPARATOR)+1);
       
   806 	iMapFileInfo.iSymbolPCEntrySet.push_back(tmpEntry);
       
   807 	iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iDataSymbolCount++;
       
   808 }
       
   809 void BsymRofsSymbolProcessUnit::FlushStdOut(ostream& aOut)
       
   810 {
       
   811 	for(int i = 0; i < (int) iStdoutLog.size(); i++)
       
   812 	{
       
   813 		aOut << iStdoutLog[i];
       
   814 	}
       
   815 }
       
   816 void BsymRofsSymbolProcessUnit::FlushSymbolContent(ostream &aOut)
       
   817 {
       
   818 	iSymbolGeneratorPtr->AppendMapFileInfo(iMapFileInfo);
       
   819 }
       
   820 void BsymRofsSymbolProcessUnit::ResetContentLog()
       
   821 {
       
   822 	iStdoutLog.clear();
       
   823 	iMapFileInfo.iDbgUnitPCEntry.iPCName = "";
       
   824 	iMapFileInfo.iDbgUnitPCEntry.iDevName = "";
       
   825 	iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.Reset();
       
   826 	iMapFileInfo.iSymbolPCEntrySet.clear();
       
   827 }
       
   828 void BsymRofsSymbolProcessUnit::ProcessArmv5File( const string& fileName, ifstream& aMap ){
       
   829     aMap.seekg (0, ios::beg);
       
   830     char str[MAX_LINE];
       
   831     char outbuffer[MAX_LINE];
       
   832     aMap.getline(str,MAX_LINE);
       
   833     boost::cmatch what;
       
   834     boost::regex reg("^ARM Linker");
       
   835     if(!regex_search(str, what, reg)) {
       
   836         sprintf(outbuffer, "\nWarning: expecting %s to be generated by ARM linker\n", fileName.c_str());
       
   837         iStdoutLog.push_back(outbuffer);
       
   838 	return;
       
   839     }
       
   840     reg.assign("Global Symbols");
       
   841     boost::regex bss_search("^\\s*\\.bss\\s*0x(\\S+)\\s*.*$");
       
   842     bool hasValue = false;
       
   843     string bssStart;
       
   844     TUint32 bssSection = 0;
       
   845     while(aMap.getline(str,MAX_LINE)) {
       
   846 	if(!hasValue && regex_search(str, what, bss_search))
       
   847 	{
       
   848 	    hasValue = true;
       
   849             bssStart.assign(what[1].first,what[1].second-what[1].first);
       
   850 	}
       
   851         if(regex_search(str, what, reg)) {
       
   852             break;
       
   853         }
       
   854     }
       
   855     if(!bssStart.empty())
       
   856     {
       
   857 	bssSection = strtol(bssStart.c_str(), NULL, 16);
       
   858     }
       
   859     reg.assign("^\\s*(.+)\\s*0x(\\S+)\\s+[^\\d]*(\\d+)\\s+(.*)$");
       
   860     string sSym,sTmp,sSection,scopeName, symName;
       
   861     boost::regex regScope("^\\s*(\\w+)\\s*::\\s*(.*)$");
       
   862     unsigned int addr,size,baseOffset = 0;
       
   863     map<unsigned int, TSymbolPCEntry> syms;
       
   864     TUint32 dataStart = 0x400000;
       
   865     while(aMap.getline(str,MAX_LINE)) {
       
   866         if(regex_search(str, what, reg)) {
       
   867             sSym.assign(what[1].first,what[1].second-what[1].first);
       
   868             sTmp.assign(what[2].first,what[2].second-what[2].first);
       
   869             addr = strtol(sTmp.c_str(), NULL, 16);
       
   870             sTmp.assign(what[3].first,what[3].second-what[3].first);
       
   871             size = strtol(sTmp.c_str(), NULL, 10);
       
   872             sSection.assign(what[4].first,what[4].second-what[4].first);
       
   873             if(sSection.find("(StubCode)") != string::npos)
       
   874                 size = 8;
       
   875             if(addr > 0) {
       
   876                 if(baseOffset == 0)
       
   877                     baseOffset = addr;
       
   878                 unsigned int k = addr - baseOffset;
       
   879                 if( (syms.find(k) == syms.end()) || size != 0)
       
   880                 {
       
   881                 	TSymbolPCEntry tmpEntry;
       
   882                 	if(regex_search(sSym, what, regScope))
       
   883                 	{
       
   884                 		scopeName.assign(what[1].first, what[1].second-what[1].first);
       
   885                 		symName.assign(what[2].first, what[2].second-what[2].first);
       
   886                 		tmpEntry.iScopeName = scopeName;
       
   887                 		tmpEntry.iName = symName;
       
   888                 		tmpEntry.iSecName = sSection;
       
   889                 	}
       
   890                 	else
       
   891                 	{
       
   892                 		tmpEntry.iScopeName = "";
       
   893                 		tmpEntry.iName = sSym;
       
   894                 		tmpEntry.iSecName = sSection;
       
   895                 	}
       
   896                 	tmpEntry.iSymbolEntry.iAddress = k;
       
   897                 	tmpEntry.iSymbolEntry.iLength = size;
       
   898 			syms[k]=tmpEntry;
       
   899                 }
       
   900 
       
   901             }
       
   902             // end of addr>0
       
   903         }
       
   904         // end of regex_search
       
   905     }
       
   906 
       
   907     map<unsigned int, TSymbolPCEntry>::iterator it;
       
   908     for(it = syms.begin(); it != syms.end(); it++) {
       
   909 	    unsigned int addr = it->first;
       
   910 	    if(addr < dataStart)
       
   911 	    {
       
   912 	        iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iCodeSymbolCount++;
       
   913 	    }
       
   914 	    else
       
   915 	    {
       
   916 	        if(bssSection > 0 && addr >= bssSection)
       
   917 		{
       
   918 		    iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iBssSymbolCount++;
       
   919 	        }
       
   920 		else
       
   921 	        {
       
   922 		    iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iDataSymbolCount++;
       
   923 	        }
       
   924 	    }
       
   925             iMapFileInfo.iSymbolPCEntrySet.push_back(it->second);
       
   926     }
       
   927 }
       
   928 void BsymRofsSymbolProcessUnit::ProcessGcceOrArm4File( const string& fileName, ifstream& aMap ){
       
   929     aMap.seekg (0, ios_base::beg);
       
   930     char str[MAX_LINE];
       
   931     char outbuffer[MAX_LINE];
       
   932     aMap.getline(str,MAX_LINE);
       
   933     boost::cmatch what;
       
   934     boost::regex reg("^\\.text\\s+");
       
   935     while(aMap.getline(str,MAX_LINE)) {
       
   936         if(regex_search(str, what, reg)) {
       
   937             break;
       
   938         }
       
   939     }
       
   940 
       
   941     reg.assign("^\\.text\\s+(\\w+)\\s+\\w+");
       
   942     if(!regex_search(str, what, reg)) {
       
   943         sprintf(outbuffer, "ERROR: Can't get .text section info for \"%s\"\n",fileName.c_str());
       
   944         iStdoutLog.push_back(outbuffer);
       
   945     }
       
   946     else {
       
   947         string sTmp, sLibFile;
       
   948         sTmp.assign(what[1].first,what[1].second-what[1].first);
       
   949         unsigned int imgText = strtol(sTmp.c_str(), NULL, 16);
       
   950 
       
   951         reg.assign("^LONG 0x.*", boost::regex::icase);
       
   952         boost::cmatch what1;
       
   953         boost::regex reg1("^\\s(\\.text)?\\s+(0x\\w+)\\s+(0x\\w+)\\s+(.*)$", boost::regex::icase);
       
   954         boost::regex reg2("^\\s+(\\w+)\\s\\s+([a-zA-Z_].+)", boost::regex::icase);
       
   955         boost::regex reg3(".*lib\\(.*d\\d*s_?\\d{5}.o\\)$", boost::regex::icase);
       
   956 
       
   957         map<unsigned int,string> syms;
       
   958         unsigned int addr, len, stubhex;
       
   959 
       
   960         while(aMap.getline(str,MAX_LINE)) {
       
   961             if(strlen(str) == 0)
       
   962                 break;
       
   963             else if(regex_search(str, what, reg1)) {
       
   964                 sLibFile.assign(what[4].first,what[4].second-what[4].first);
       
   965                 if(!regex_search(sLibFile, what1, reg)) {
       
   966                     sTmp.assign(what[2].first,what[2].second-what[2].first);
       
   967                     addr = strtol(sTmp.c_str(), NULL, 16);
       
   968                     sTmp.assign(what[3].first,what[3].second-what[3].first);
       
   969                     len = strtol(sTmp.c_str(), NULL, 16);
       
   970                     syms[addr+len] = "";
       
   971                     if(regex_search(sLibFile, what, reg3)) {
       
   972                         stubhex = addr;
       
   973                     }
       
   974                 }
       
   975             }
       
   976             else if(regex_search(str, what, reg2)) {
       
   977                 sTmp.assign(what[1].first,what[1].second-what[1].first);
       
   978                 addr = strtol(sTmp.c_str(), NULL, 16);
       
   979                 sTmp.assign(what[2].first,what[2].second-what[2].first);
       
   980                 syms[addr] = (addr == stubhex)? ("stub "+sTmp) : sTmp;
       
   981             }
       
   982         }
       
   983 
       
   984         map<unsigned int,string>::iterator it = syms.begin();
       
   985         map<unsigned int,string>::iterator itp = it++;
       
   986         TSymbolPCEntry tmpSymbolEntry;
       
   987         for(; it != syms.end(); itp = it++) {
       
   988            if(itp->second != "") {
       
   989                 tmpSymbolEntry.iSymbolEntry.iAddress = itp->first-imgText;
       
   990                 tmpSymbolEntry.iSymbolEntry.iLength = it->first-itp->first;
       
   991                 tmpSymbolEntry.iName = it->second;
       
   992 		iMapFileInfo.iDbgUnitPCEntry.iDbgUnitEntry.iCodeSymbolCount++;
       
   993                 iMapFileInfo.iSymbolPCEntrySet.push_back(tmpSymbolEntry);
       
   994             }
       
   995         }
       
   996     }
       
   997 }