imgtools/romtools/rofsbuild/symbolprocessunit.cpp
author Ross Qin <ross.qin@nokia.com>
Tue, 02 Nov 2010 16:47:21 +0800
changeset 672 bc9ef8cca9ec
parent 654 7c11c3d8d025
permissions -rw-r--r--
revert the change to rofsbuild image format, but add checking codes to prevent address overflow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     1
/*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
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:
diff changeset
     3
* All rights reserved.
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
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:
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:
diff changeset
     6
* which accompanies this distribution, and is available
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
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:
diff changeset
     8
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    11
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    12
* Contributors:
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    13
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    14
* Description: 
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    15
*
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    16
*/
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    17
#include <boost/regex.hpp>
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    18
#include "symbolprocessunit.h"
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    19
#include "e32image.h"
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    20
#define MAX_LINE 65535
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    21
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    22
#if defined(__LINUX__)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    23
#define PATH_SEPARATOR '/'
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    24
#else
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    25
#define PATH_SEPARATOR '\\'
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    26
#endif
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    27
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    28
void CommenSymbolProcessUnit::ProcessExecutableFile(const string& aFile)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    29
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    30
	ResetContentLog();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    31
	char str[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    32
	string outString;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    33
	outString = "\nFrom    ";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    34
	outString += aFile + "\n\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    35
	iSymbolContentLog.push_back(outString);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    36
	string mapFile2 = aFile+".map";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    37
	size_t dot = aFile.rfind('.');
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    38
	string mapFile = aFile.substr(0,dot)+".map";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    39
	ifstream fMap;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    40
	fMap.open(mapFile2.c_str());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    41
	if(!fMap.is_open()) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    42
		fMap.open(mapFile.c_str());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    43
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    44
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    45
	if(!fMap.is_open()) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    46
		sprintf(str, "%s\nWarning: Can't open \"%s\" or \"%s\"\n",aFile.c_str(),mapFile2.c_str(),mapFile.c_str());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    47
		iStdoutLog.push_back(str);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    48
	    int binSize = GetSizeFromBinFile(aFile);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    49
	    memset(str,0,sizeof(str));
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    50
	    sprintf(str,"%04x", binSize);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    51
	    outString = "00000000    ";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    52
	    outString += str;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    53
	    outString += "    ";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    54
	    outString += aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    55
	    iSymbolContentLog.push_back(outString);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    56
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    57
	else {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    58
		if(!fMap.good()) fMap.clear();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    59
	    boost::regex regARMV5("ARMV5", boost::regex::icase);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    60
	    boost::regex regGCCEoARMV4("(GCCE|ARMV4)", boost::regex::icase);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    61
	    boost::cmatch what;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    62
	    if(regex_search(aFile, what, regARMV5)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    63
	        ProcessArmv5File(aFile, fMap);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    64
	    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    65
	    else if(regex_search(aFile, what, regGCCEoARMV4)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    66
	        ProcessGcceOrArm4File(aFile, fMap);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    67
	    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    68
	    else {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    69
	        sprintf(str, "\nWarning: cannot determine linker type used to create %s\n",aFile.c_str());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    70
	        iStdoutLog.push_back(str);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    71
	        outString = "00000000    0000    ";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    72
	        outString += aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    73
	        iSymbolContentLog.push_back(outString);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    74
	        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    75
	    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    76
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    77
void CommenSymbolProcessUnit::ProcessDataFile(const string& aFile)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    78
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    79
	ResetContentLog();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    80
	string line = "\nFrom    "+aFile+"\n\n00000000    0000    "+aFile.substr(aFile.rfind(PATH_SEPARATOR)+1)+"\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    81
	iSymbolContentLog.push_back(line);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    82
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    83
void CommenSymbolProcessUnit::FlushStdOut(ostream& aOut)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    84
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    85
	for(int i = 0; i < (int) iStdoutLog.size(); i++)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    86
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    87
		aOut << iStdoutLog[i];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    88
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    89
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    90
void CommenSymbolProcessUnit::FlushSymbolContent(ostream &aOut)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    91
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    92
	for(int i = 0; i < (int) iSymbolContentLog.size(); i++)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    93
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    94
		aOut << iSymbolContentLog[i];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    95
	}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    96
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    97
void CommenSymbolProcessUnit::ResetContentLog()
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    98
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
    99
	iStdoutLog.clear();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   100
	iSymbolContentLog.clear();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   101
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   102
void CommenSymbolProcessUnit::ProcessArmv5File( const string& fileName, ifstream& aMap ){
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   103
    aMap.seekg (0, ios::beg);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   104
    char str[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   105
    char outbuffer[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   106
    string outString;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   107
    aMap.getline(str,MAX_LINE);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   108
    boost::cmatch what;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   109
    boost::regex reg("^ARM Linker");
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   110
    if(!regex_search(str, what, reg)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   111
        sprintf(outbuffer, "\nWarning: expecting %s to be generated by ARM linker\n", fileName.c_str());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   112
        iStdoutLog.push_back(outbuffer);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   113
        outString = "00000000    0000    "+fileName.substr(fileName.rfind(PATH_SEPARATOR)+1)+"\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   114
        iSymbolContentLog.push_back(outString);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   115
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   116
    reg.assign("Global Symbols");
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   117
    while(aMap.getline(str,MAX_LINE)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   118
        if(regex_search(str, what, reg)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   119
            break;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   120
        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   121
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   122
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   123
    reg.assign("^\\s*(.+)\\s*0x(\\S+)\\s+[^\\d]*(\\d+)\\s+(.*)$");
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   124
    string sSym,sTmp,sSection;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   125
    unsigned int addr,size,baseOffset = 0;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   126
    map<unsigned int,string> syms;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   127
    char symString[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   128
    while(aMap.getline(str,MAX_LINE)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   129
        if(regex_search(str, what, reg)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   130
            sSym.assign(what[1].first,what[1].second-what[1].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   131
            sTmp.assign(what[2].first,what[2].second-what[2].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   132
            addr = strtol(sTmp.c_str(), NULL, 16);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   133
            sTmp.assign(what[3].first,what[3].second-what[3].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   134
            size = strtol(sTmp.c_str(), NULL, 10);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   135
            sSection.assign(what[4].first,what[4].second-what[4].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   136
            if(sSection.find("(StubCode)") != string::npos)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   137
                size = 8;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   138
            if(addr > 0) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   139
                memset(symString,0,sizeof(symString));
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   140
                sprintf(symString,"%04x    ",size);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   141
                outString = symString;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   142
                outString += sSym+" ";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   143
                outString += sSection;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   144
                if(baseOffset == 0)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   145
                    baseOffset = addr;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   146
                unsigned int k = addr - baseOffset;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   147
                if( (syms.find(k) == syms.end()) || size != 0)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   148
                    syms[k] = outString;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   149
            }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   150
            // end of addr>0
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   151
        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   152
        // end of regex_search
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   153
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   154
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   155
    map<unsigned int,string>::iterator it;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   156
    for(it = syms.begin(); it != syms.end(); it++) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   157
        memset(str,0,sizeof(str));
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   158
        sprintf(str,"%08x",it->first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   159
        outString = str;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   160
        outString += "    ";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   161
        outString += it->second+"\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   162
        iSymbolContentLog.push_back(outString);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   163
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   164
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   165
void CommenSymbolProcessUnit::ProcessGcceOrArm4File( const string& fileName, ifstream& aMap ){
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   166
    aMap.seekg (0, ios_base::beg);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   167
    char str[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   168
    char outbuffer[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   169
    aMap.getline(str,MAX_LINE);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   170
    boost::cmatch what;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   171
    boost::regex reg("^\\.text\\s+");
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   172
    while(aMap.getline(str,MAX_LINE)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   173
        if(regex_search(str, what, reg)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   174
            break;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   175
        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   176
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   177
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   178
    reg.assign("^\\.text\\s+(\\w+)\\s+\\w+");
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   179
    if(!regex_search(str, what, reg)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   180
        sprintf(outbuffer, "ERROR: Can't get .text section info for \"%s\"\n",fileName.c_str());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   181
        iStdoutLog.push_back(outbuffer);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   182
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   183
    else {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   184
        string sTmp, sLibFile;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   185
        sTmp.assign(what[1].first,what[1].second-what[1].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   186
        unsigned int imgText = strtol(sTmp.c_str(), NULL, 16);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   187
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   188
        reg.assign("^LONG 0x.*", boost::regex::icase);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   189
        boost::cmatch what1;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   190
        boost::regex reg1("^\\s(\\.text)?\\s+(0x\\w+)\\s+(0x\\w+)\\s+(.*)$", boost::regex::icase);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   191
        boost::regex reg2("^\\s+(\\w+)\\s\\s+([a-zA-Z_].+)", boost::regex::icase);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   192
        boost::regex reg3(".*lib\\(.*d\\d*s_?\\d{5}.o\\)$", boost::regex::icase);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   193
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   194
        map<unsigned int,string> syms;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   195
        unsigned int addr, len, stubhex;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   196
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   197
        while(aMap.getline(str,MAX_LINE)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   198
            if(strlen(str) == 0)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   199
                break;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   200
            else if(regex_search(str, what, reg1)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   201
                sLibFile.assign(what[4].first,what[4].second-what[4].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   202
                if(!regex_search(sLibFile, what1, reg)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   203
                    sTmp.assign(what[2].first,what[2].second-what[2].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   204
                    addr = strtol(sTmp.c_str(), NULL, 16);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   205
                    sTmp.assign(what[3].first,what[3].second-what[3].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   206
                    len = strtol(sTmp.c_str(), NULL, 16);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   207
                    syms[addr+len] = "";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   208
                    if(regex_search(sLibFile, what, reg3)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   209
                        stubhex = addr;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   210
                    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   211
                }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   212
            }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   213
            else if(regex_search(str, what, reg2)) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   214
                sTmp.assign(what[1].first,what[1].second-what[1].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   215
                addr = strtol(sTmp.c_str(), NULL, 16);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   216
                sTmp.assign(what[2].first,what[2].second-what[2].first);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   217
                syms[addr] = (addr == stubhex)? ("stub "+sTmp) : sTmp;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   218
            }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   219
        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   220
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   221
        map<unsigned int,string>::iterator it = syms.begin();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   222
        map<unsigned int,string>::iterator itp = it++;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   223
        string outString;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   224
        for(; it != syms.end(); itp = it++) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   225
            if(itp->second != "") {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   226
                memset(str,0,sizeof(str));
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   227
                sprintf(str,"%08x    %04x    ",(itp->first-imgText), (it->first-itp->first));
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   228
                outString = str;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   229
                outString += it->second+"\n";
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   230
                iSymbolContentLog.push_back(outString);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   231
            }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   232
        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   233
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   234
}
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   235
int CommenSymbolProcessUnit::GetSizeFromBinFile( const string& fileName ){
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   236
    TInt ret = 0;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   237
    char outbuffer[MAX_LINE];
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   238
    ifstream aIf(fileName.c_str(), ios_base::binary);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   239
    if( !aIf.is_open() ) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   240
        printf(outbuffer, "Warning: Cannot open file \n");
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   241
        iStdoutLog.push_back(outbuffer);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   242
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   243
    else {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   244
        E32ImageFile e32Image;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   245
        TUint32 aSz;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   246
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   247
        aIf.seekg(0,ios_base::end);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   248
        aSz = aIf.tellg();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   249
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   250
        e32Image.Adjust(aSz);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   251
        e32Image.iFileSize = aSz;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   252
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   253
        aIf.seekg(0,ios_base::beg);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   254
        aIf >> e32Image;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   255
        ret = e32Image.iOrigHdr->iCodeSize;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   256
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   257
    return ret;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents:
diff changeset
   258
}