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