imgtools/romtools/rombuild/symbolgenerator.cpp
author kelvzhu
Wed, 14 Jul 2010 16:22:24 +0800
changeset 613 839712f5a78c
parent 600 6d08f4a05d93
child 654 7c11c3d8d025
permissions -rw-r--r--
fixed defect 1412
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
#include <e32rom.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
#include <algorithm>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
#include "symbolgenerator.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
#include "r_rom.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
#include <string.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
#include "h_utl.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
typedef boost::unique_lock<boost::mutex>  scoped_lock ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
typedef boost::lock_guard<boost::mutex> guarded_lock ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
SymbolGenerator::SymbolGenerator(const char* aSymbolFileName, int aMultiThreadsCount/* = 1*/) :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
iOutput(aSymbolFileName,ios_base::out |ios_base::binary |  ios_base::trunc) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
	if(iOutput.is_open()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
		if(aMultiThreadsCount < 1)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
			aMultiThreadsCount = 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
		for(int i = 0 ; i < aMultiThreadsCount ; i++){		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
			iThreads.add_thread(new boost::thread(ThreadFunc,this));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
	else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
		cerr << "\nWarning: Can't write data to \""<<aSymbolFileName << "\" ! \nPlease make sure this file is not locked by other application or you have write permission!"<<endl;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
	} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
void SymbolGenerator::WaitThreads() {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
	iThreads.join_all(); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
SymbolGenerator::~SymbolGenerator() {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
	if(iOutput.is_open()){		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
		iOutput.flush();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
		iOutput.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	for(vector<char*>::iterator i = iErrMsgs.begin() ; i != iErrMsgs.end() ; i++){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
		char* msg = *i ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
		cerr << msg ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
		delete []msg ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
	iErrMsgs.clear(); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
void SymbolGenerator::AddEntry(const SymGenContext& aEntry){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
	if(iOutput.is_open()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
		guarded_lock lock(iQueueMutex); 		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
		iEntries.push(aEntry);		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
		iCond.notify_all();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
void SymbolGenerator::ThreadFunc(SymbolGenerator* aInst) {		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
		SymGenContext entry ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
		while(1){ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
			entry.iFileName = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
			if(1) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
				scoped_lock lock(aInst->iQueueMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
				while(aInst->iEntries.empty()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
						aInst->iCond.wait(lock);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
				}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
				entry = aInst->iEntries.front();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
				if(0 == entry.iFileName)  // end , exit
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
					return ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
					
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
				aInst->iEntries.pop();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
			aInst->ProcessEntry(entry);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
#define MAX_LINE_LENGTH 65535 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
#define SKIP_WS(p)	 while((*p) == ' ' ||  (*p) == '\t') (p)++ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
#define FIND_WS(p)	 while((*p) != ' ' &&  (*p) != '\t' && (*p) != 0) (p)++ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
static void split(char* str, vector<char*>& result) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	result.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
	while(*str) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
		SKIP_WS(str);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
		char* saved = str ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
		FIND_WS(str);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
		bool end = (0 == *str);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
		*str = 0 ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
		if(saved != str)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
			result.push_back(saved);		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		if(!end) str ++ ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
	}	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
static void make_lower(char* str){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	while(*str){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
		if(*str >= 'A' && *str >= 'Z') {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
			*str += ('a' - 'A');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
		str++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
bool SymbolGenerator::ProcessEntry(const SymGenContext& aContext) {	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	size_t allocBytes ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
	if(aContext.iExecutable ) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
		string mapFileName(aContext.iFileName);	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
		mapFileName += ".map";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
		ifstream ifs(mapFileName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
		if(!ifs.is_open()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
			int index = mapFileName.length() - 5 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
			int count = 1 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
			while(index > 0 && mapFileName.at(index) != '.'){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
				index -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
				count ++ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
			mapFileName.erase(index,count);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
			ifs.open(mapFileName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
		if(!ifs.is_open()){		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
			guarded_lock lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
			allocBytes = mapFileName.length() + 60 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
			char* msg = new char[ allocBytes] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
			snprintf(msg,allocBytes,"\nWarning: Can't open \"%s.map\"\n",aContext.iFileName );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
			iErrMsgs.push_back(msg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
			msg = new char[allocBytes] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
			int n = snprintf(msg,allocBytes,"%08x    %04x    %s\r\n",(unsigned int)aContext.iCodeAddress,(unsigned int)aContext.iTotalSize,aContext.iFileName);			
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
			iOutput.write(msg,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
			iOutput.flush();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
			return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
		} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
		if(!ifs.good()) ifs.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
		char buffer[100]; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
		*buffer = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
		//See if we're dealing with the RVCT output
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
		ifs.getline(buffer,100);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
		if(!ifs.good()) { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
			ifs.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
			guarded_lock lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
			allocBytes = mapFileName.length() + 60;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
			char* msg = new char[allocBytes] ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
			snprintf(msg,allocBytes,"\nWarning: File \"%s\" is opened yet can not be read!",mapFileName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
			iErrMsgs.push_back(msg);  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
			return false ;			 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
		if(strncmp(buffer,"ARM Linker",10) == 0){  			
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
			return ProcessARMV5Map(ifs,aContext);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
		// See if we're dealing with the GCC output
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
		else if ( 0 == strncmp(buffer,"Archive member included",23)){ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
			return ProcessGCCMap(ifs,aContext);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
		else { // Must be x86 output
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
			ifs.seekg(0,ios_base::beg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
			return ProcessX86Map(ifs,aContext);		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
	else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
		const char* fileName = aContext.iFileName;	  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
		size_t len = strlen(fileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
		size_t index = len - 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
		while(index > 0 && (fileName[index] != '\\' && fileName[index] != '/'))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
			index -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
		const char* basename = fileName + index + 1  ;		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
		allocBytes = (len << 1) + 40 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
		char* msg = new char[allocBytes] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
		int n = snprintf(msg,allocBytes,"\r\nFrom    %s\r\n\r\n%08x    0000    %s\r\n", fileName ,(unsigned int)aContext.iDataAddress,basename);	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
		guarded_lock lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
		iOutput.write(msg,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
		iOutput.flush();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
		delete []msg ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
		return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
struct ArmSymbolInfo {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
	string name ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
	TUint size ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	string section ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
typedef multimap<TUint32,ArmSymbolInfo> ArmSymMap ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
bool SymbolGenerator::ProcessARMV5Map(ifstream& aStream, const SymGenContext& aContext) {	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
	string symName ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
	ArmSymMap symbols ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
	vector<char*> words ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
	ArmSymbolInfo info;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
	char* lineStart ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
	char buffer[MAX_LINE_LENGTH];  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	while(aStream.good() && (!aStream.eof())){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
		*buffer = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
		aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
		lineStart = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
		SKIP_WS(lineStart);	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
		if(strstr(lineStart,"Global Symbols"))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
			break ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
		char* armstamp = strstr(lineStart,"ARM Code");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
		if(0 == armstamp)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
			armstamp = strstr(lineStart,"Thumb Code") ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
		if(0 == armstamp) continue ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
		*(armstamp - 1) = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
		char* hexStr = lineStart ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
		char* nameEnd;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
		while(1) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
			hexStr = strstr(hexStr,"0x");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
			if(0 == hexStr) break ; 		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
			nameEnd = hexStr - 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
			if(*nameEnd == ' ' || *nameEnd == '\t') break ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
			hexStr += 2 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
		}	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
		if(0 == hexStr) continue ; 	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
		while(nameEnd > lineStart && (*nameEnd == ' ' || *nameEnd == '\t'))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
			nameEnd -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
		nameEnd[1] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
		info.name = lineStart;		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
		char* temp ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
		TUint32 addr = strtoul(hexStr + 2,&temp,16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
		char* decStr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
		if(*armstamp == 'A')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
			decStr = armstamp + 9 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
		else 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
			decStr = armstamp + 11 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
		SKIP_WS(decStr);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
		info.size = strtoul(decStr,&temp,10);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
		SKIP_WS(temp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
		info.section = temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
		if(info.section.find("(StubCode)") != string::npos )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
			info.size = 8 ; 			
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
		if(addr > 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
			symbols.insert(pair<TUint32,ArmSymbolInfo>(addr,info));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
	}	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
	size_t lenOfFileName = strlen(aContext.iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
	while(aStream.good() && (!aStream.eof())){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
		*buffer = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
		aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
		lineStart = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
		SKIP_WS(lineStart); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
		char* hexStr = lineStart ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
		char* nameEnd;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
		while(1) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
			hexStr = strstr(hexStr,"0x");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
			if(0 == hexStr) break ; 		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
			nameEnd = hexStr - 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
			if(*nameEnd == ' ' || *nameEnd == '\t') 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
				break ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
			hexStr += 2 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
		}	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
		if(0 == hexStr) continue ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
		while(nameEnd > lineStart && (*nameEnd == ' ' || *nameEnd == '\t')){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
			nameEnd -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
		nameEnd[1] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
		info.name = lineStart; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
		char *temp ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
		TUint32 addr = strtoul(hexStr + 2,&temp,16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
		while(*temp < '0' || *temp > '9' )//[^\d]*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
			temp++ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
		char* decStr = temp ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
		info.size = strtoul(decStr,&temp,10);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
		SKIP_WS(temp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
		info.section = temp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
		if(info.section.find("(StubCode)") != string::npos )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
			info.size = 8 ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
		if(addr > 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
			symbols.insert(pair<TUint32,ArmSymbolInfo>(addr,info));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
		} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
	TUint32 textSectAddr = 0x00008000;  // .text gets linked at 0x00008000
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
	TUint32 dataSectAddr = 0x00400000 ; // .data gets linked at 0x00400000
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
	vector<pair<int,char*> > lines ;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
	size_t allocBytes;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
	for( ArmSymMap::iterator it = symbols.begin(); it != symbols.end() ; it++){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
		TUint32 thisAddr = it->first ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
		TUint32 romAddr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
		ArmSymbolInfo& info = it->second; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
		if (thisAddr >= textSectAddr && thisAddr <= (textSectAddr + aContext.iTextSize)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
				romAddr = thisAddr - textSectAddr + aContext.iCodeAddress ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
		} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
		else if ( aContext.iDataAddress && 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
			( thisAddr >= dataSectAddr && thisAddr <= (dataSectAddr + aContext.iTextSize))) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
			romAddr = thisAddr-dataSectAddr + aContext.iDataBssLinearBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
		} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
		else if ( aContext.iDataBssLinearBase && 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
			( thisAddr >= dataSectAddr && thisAddr <= (dataSectAddr+ aContext.iTotalDataSize))) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
			romAddr = thisAddr - dataSectAddr + aContext.iDataBssLinearBase;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
		} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
		else { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
			guarded_lock  lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
			allocBytes = info.name.length() + 60;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
			char* msg = new char[allocBytes] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
			snprintf(msg,allocBytes,"\r\nWarning: Symbol %s @ 0x%08x not in text or data segments\r\n", \
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
				info.name.c_str() ,(unsigned int)thisAddr) ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
			iErrMsgs.push_back(msg);	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
			allocBytes = lenOfFileName + 80;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
			msg = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
			snprintf(msg,allocBytes,"Warning:  The map file for binary %s is out-of-sync with the binary itself\r\n\r\n",aContext.iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
			iErrMsgs.push_back(msg);	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
			continue ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
		allocBytes =  info.section.length() + info.name.length() + 140;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
		char* outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
		int len = snprintf(outputLine,allocBytes,"%08x    %04x    %-40s  %s\r\n",(unsigned int)romAddr,info.size,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
			info.name.c_str(),info.section.c_str()); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
		if((size_t)len > allocBytes) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
			allocBytes = len + 4 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
			delete []outputLine;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
			outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
			len = snprintf(outputLine,allocBytes,"%08x    %04x    %-40s  %s\r\n",(unsigned int)romAddr,info.size,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
			info.name.c_str(),info.section.c_str()); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
		lines.push_back(pair<int,char*>(len,outputLine));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
	}  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
	guarded_lock lock(iFileMutex);	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
	allocBytes = lenOfFileName + 40;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
	char* outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
	int n = snprintf(outputLine,allocBytes,"\r\nFrom    %s\r\n\r\n",aContext.iFileName); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
	iOutput.write(outputLine,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
	delete []outputLine ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
	for (vector<pair<int,char*> >::iterator i = lines.begin() ; i < lines.end(); i ++ ) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
		int len = i->first ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
		char* line = i->second; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
		iOutput.write(line,len);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
		delete []line ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
	}	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
	iOutput.flush();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
	return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
template<typename M, typename K,typename V> 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
static void put_to_map(M& m,const K& k, const V& v) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
	typedef typename M::iterator iterator;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
	iterator it = m.find(k);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
	if(m.end() == it){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
		m.insert(pair<K,V>(k,v));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
	else { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
		it->second = v ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
	}	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
bool  SymbolGenerator::ProcessGCCMap(ifstream& aStream, const SymGenContext& aContext){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
 	char* lineStart; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
	vector<char*> words ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
	char buffer[MAX_LINE_LENGTH];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
	while(aStream.good() && (!aStream.eof())){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
		aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
		lineStart = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
		SKIP_WS(lineStart);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
		if( 0 == strncmp(lineStart,".text",5)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
			lineStart += 5;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
			break ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
		}		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
	split(lineStart,words);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
	TUint32 codeAddr , codeSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
	size_t allocBytes ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
	if(words.size() != 2 ||
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
	KErrNone != Val(codeAddr,words.at(0)) || 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
	KErrNone != Val(codeSize,words.at(1))) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
		allocBytes = strlen(aContext.iFileName) + 60;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
		char* msg = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
		snprintf(msg,allocBytes,"\nError: Can't get .text section info for \"%s\"\r\n",aContext.iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
		guarded_lock lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
		iErrMsgs.push_back(msg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
	map<TUint32,string> symbols ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
	TUint32 stubHex = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
	//Slurp symbols 'til the end of the text section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
	while(aStream.good() && (!aStream.eof())){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
		aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
		lineStart = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
		SKIP_WS(lineStart); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
		if(0 == *lineStart) break ; //blank line marks the end of the text section
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
		// .text <addr> <len>  <library(member)>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
		// .text$something
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
		//       <addr> <len>  <library(member)>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
		//       <addr> <len>  LONG 0x0
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
		// (/^\s(\.text)?\s+(0x\w+)\s+(0x\w+)\s+(.*)$/io)	 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
		if(strncmp(lineStart,".text",5) == 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
			lineStart += 5 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
			SKIP_WS(lineStart);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
		char* hex1 = NULL ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
		char* hex2 = NULL ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
		char* strAfterhex1 = NULL ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
		TUint32 addr,size ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
		if(strncmp(lineStart,"0x",2) == 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
			hex1 = lineStart + 2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
			char* temp ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
			addr = strtoul(hex1,&temp,16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
			SKIP_WS(temp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
			strAfterhex1 = temp ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
			if(strncmp(temp,"0x",2) == 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
				hex2 = temp + 2 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
		if(NULL != hex2){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
			char* libraryfile ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
			size = strtoul(hex2,&libraryfile,16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
			SKIP_WS(libraryfile);  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
			TUint32 key = addr + size ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
			put_to_map(symbols,key,string(""));//impossible symbol as end marker 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
			make_lower(libraryfile); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
			// EUSER.LIB(ds01423.o)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
			// EUSER.LIB(C:/TEMP/d1000s_01423.o)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
			size_t len = strlen(libraryfile);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
			char* p1 = strstr(libraryfile,".lib(");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
			if(NULL == p1) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
				continue ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
			p1 += 5;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
			if(strcmp(libraryfile + len - 3,".o)")!= 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
				continue ;		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
			len -= 3 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
			libraryfile[len] = 0; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
			if(EFalse == IsValidNumber(libraryfile + len - 5))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
				continue ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
			len -= 7 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
			if('_' == libraryfile[len])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
				len -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
			if('s' != libraryfile[len])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
				continue ;		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
			char* p2 = libraryfile + len - 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
			while(p2 > p1 ) { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
				if(*p2 < '0' || *p2 > '9')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
					break ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
				p2 -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
			if(*p2 != 'd') 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
				continue ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
			stubHex = addr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
		else if(NULL != hex1 && NULL != strAfterhex1){ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
			//#  <addr>  <symbol name possibly including spaces>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
			//(/^\s+(\w+)\s\s+([a-zA-Z_].+)/o) 			 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
			char* symName = strAfterhex1; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
			if((*symName >= 'A' && *symName <= 'Z') ||
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   429
				(*symName >= 'a' && *symName <= 'z') || *symName == '_') {				 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   430
				string symbol(symName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   431
				if(addr == stubHex) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   432
					symbol.insert(0,"stub ");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   433
			 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   434
				put_to_map(symbols,addr,symbol);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   435
				 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   436
			}			
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   437
		}		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   438
	}  
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   439
	map<TUint32,string>::iterator it = symbols.begin();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   440
	TUint32 lastAddr = it->first;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   441
	string lastSymName = it->second;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   442
	vector<pair<int,char*> >lines ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   443
	it ++ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   444
	while(it != symbols.end()) {		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   445
		TUint32 addr = it->first ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   446
		unsigned int fixedupAddr = lastAddr - codeAddr + aContext.iCodeAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   447
		TUint size = addr - lastAddr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   448
		if(!lastSymName.empty()) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   449
			allocBytes = lastSymName.length() + 40;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   450
			char* outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   451
			int n = snprintf(outputLine,allocBytes,"%08x    %04x    %s\r\n", fixedupAddr,size,lastSymName.c_str()); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   452
			lines.push_back(pair<int,char*>(n,outputLine));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   453
		}		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   454
		lastAddr = addr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   455
		lastSymName = it->second;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   456
		it ++ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   457
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   458
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   459
	guarded_lock lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   460
	allocBytes = strlen(aContext.iFileName) + 40;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   461
	char* outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   462
	int n = snprintf(outputLine,allocBytes,"\r\nFrom    %s\r\n\r\n",aContext.iFileName); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   463
	iOutput.write(outputLine,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   464
	delete []outputLine ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   465
	vector<pair<int,char*> >::iterator i; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   466
	for ( i = lines.begin() ; i < lines.end(); i ++ ) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   467
		int len = i->first ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   468
		char* line = i->second ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   469
		iOutput.write(line,len);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   470
		delete []line ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   471
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   472
	iOutput.flush();	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   473
	return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   474
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   475
bool SymbolGenerator::ProcessX86Map(ifstream& aStream, const SymGenContext& aContext) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   476
	char buffer[MAX_LINE_LENGTH]; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   477
	char* lineStart; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   478
	while(aStream.good() && (!aStream.eof())){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   479
		aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   480
		lineStart = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   481
		SKIP_WS(lineStart);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   482
		if( 0 == strncmp(lineStart,"Address",7)) { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   483
			break ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   484
		}		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   485
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   486
	aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   487
	string lastName ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   488
	TUint32 lastAddr = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   489
	size_t allocBytes ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   490
	vector<pair<int, char*> >lines ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   491
	while(aStream.good() && (!aStream.eof())){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   492
		aStream.getline(buffer,MAX_LINE_LENGTH);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   493
		lineStart = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   494
		SKIP_WS(lineStart);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   495
		if(0 != strncmp(lineStart,"0001:",5))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   496
			break ;		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   497
		char* end ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   498
		TUint32 addr = strtoul(lineStart + 5,&end,16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   499
		char* name = end + 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   500
		SKIP_WS(name);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   501
		end = name + 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   502
		FIND_WS(end);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   503
		*end = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   504
		if(!lastName.empty()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   505
			unsigned int size = addr - lastAddr ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   506
			unsigned int romAddr = lastAddr + aContext.iCodeAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   507
			allocBytes = lastName.length() + 40;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   508
			char* outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   509
			int n = snprintf(outputLine,allocBytes,"%08x    %04x    %s\r\n",romAddr,size,lastName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   510
			lines.push_back(pair<int, char*>(n,outputLine));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   511
		}		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   512
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   513
	guarded_lock lock(iFileMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   514
	allocBytes = strlen(aContext.iFileName) + 40;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   515
	char* outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   516
	int n = snprintf(outputLine,allocBytes,"\r\nFrom    %s\r\n\r\n",aContext.iFileName); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   517
	iOutput.write(outputLine,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   518
	delete []outputLine ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   519
	vector<pair<int,char*> >::iterator it; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   520
	for ( it = lines.begin() ; it < lines.end(); it ++ ) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   521
		int len = it->first ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   522
		char* line = it->second  ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   523
		iOutput.write(line,len);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   524
		delete []line ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   525
	}	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   526
	if(!lastName.empty()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   527
		allocBytes = lastName.length() + 40 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   528
		outputLine = new char[allocBytes];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   529
		unsigned int romAddr = lastAddr + aContext.iCodeAddress;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   530
		n = snprintf(outputLine,allocBytes,"%08x    0000    %s\r\n",romAddr,lastName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   531
		iOutput.write(outputLine,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   532
		delete []outputLine ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   533
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   534
	iOutput.flush();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   535
	return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   536
}