imgtools/romtools/rofsbuild/symbolgenerator.cpp
author kelvzhu
Mon, 18 Oct 2010 16:16:46 +0800
changeset 655 3f65fd25dfd4
parent 600 6d08f4a05d93
child 662 60be34e1b006
child 664 44b0e894b7ab
permissions -rw-r--r--
sync up SVN codes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     1
/*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     3
* All rights reserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     4
* This component and the accompanying materials are made available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     6
* which accompanies this distribution, and is available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     8
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     9
* Initial Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    10
* Nokia Corporation - initial contribution.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    11
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    12
* Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    13
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    14
* Description: 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    15
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    16
*/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    17
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <boost/regex.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#define MAX_LINE 65535
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include "symbolgenerator.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include "e32image.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#if defined(__LINUX__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#define PATH_SEPARATOR '/'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#define PATH_SEPARATOR '\\'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
boost::mutex SymbolGenerator::iMutexSingleton;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
SymbolGenerator* SymbolGenerator::iInst = NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
SymbolGenerator* SymbolGenerator::GetInstance(){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
    iMutexSingleton.lock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
    if(iInst == NULL) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
        iInst = new SymbolGenerator();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
    iMutexSingleton.unlock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
    return iInst;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
void SymbolGenerator::Release() {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
    iMutexSingleton.lock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
    if(iInst != NULL) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
        delete iInst;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
        iInst = NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
    iMutexSingleton.unlock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
void SymbolGenerator::SetSymbolFileName( const string& fileName ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
    if(iSymFile.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
        iSymFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
    string s = fileName.substr(0,fileName.rfind('.'))+".symbol";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
    printf("* Writing %s - ROFS symbol file\n", s.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
    iSymFile.open(s.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
void SymbolGenerator::AddFile( const string& fileName, bool isExecutable ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
    iMutex.lock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
    iQueueFiles.push(TPlacedEntry(fileName,isExecutable));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
    iMutex.unlock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
    iCond.notify_all();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
void SymbolGenerator::ProcessExecutable( const string& fileName ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
    char str[MAX_LINE];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
    string outString;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
    outString = "\nFrom    ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
    outString += fileName + "\n\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
    iSymFile.write(outString.c_str(),outString.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
    string mapFile2 = fileName+".map";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
    size_t dot = fileName.rfind('.');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
    string mapFile = fileName.substr(0,dot)+".map";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
    ifstream fMap;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
    fMap.open(mapFile2.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
    if(!fMap.is_open()) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
        fMap.open(mapFile.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
    if(!fMap.is_open()) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
        printf("%s\nWarning: Can't open \"%s\" or \"%s\"\n",fileName.c_str(),mapFile2.c_str(),mapFile.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
        int binSize = GetSizeFromBinFile(fileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
        memset(str,0,sizeof(str));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
        sprintf(str,"%04x", binSize);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
        outString = "00000000    ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
        outString += str;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
        outString += "    ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
        outString += fileName.substr(fileName.rfind(PATH_SEPARATOR)+1)+"\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
        iSymFile.write(outString.c_str(),outString.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
    else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
		if(!fMap.good()) fMap.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
        boost::regex regARMV5("ARMV5", boost::regex::icase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
        boost::regex regGCCEoARMV4("(GCCE|ARMV4)", boost::regex::icase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
        boost::cmatch what;
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    91
        if(regex_search(fileName.c_str(), what, regARMV5)) {
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
            ProcessArmv5File(fileName, fMap);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
        }
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    94
        else if(regex_search(fileName.c_str(), what, regGCCEoARMV4)) {
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
            ProcessGcceOrArm4File(fileName, fMap);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
        else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
            printf("\nWarning: cannot determine linker type used to create %s\n",fileName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
            outString = "00000000    0000    ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
            outString += fileName.substr(fileName.rfind(PATH_SEPARATOR)+1)+"\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
            iSymFile.write(outString.c_str(),outString.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
void SymbolGenerator::ProcessDatafile( const string& fileName ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
    string line = "\nFrom    "+fileName+"\n\n00000000    0000    "+fileName.substr(fileName.rfind(PATH_SEPARATOR)+1)+"\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
    iSymFile.write(line.c_str(),line.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
void SymbolGenerator::ProcessArmv5File( const string& fileName, ifstream& aMap ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
    aMap.seekg (0, ios::beg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
    char str[MAX_LINE];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
    string outString;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
    aMap.getline(str,MAX_LINE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
    boost::cmatch what;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
    boost::regex reg("^ARM Linker");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
    if(!regex_search(str, what, reg)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
        printf("\nWarning: expecting %s to be generated by ARM linker\n", fileName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
        outString = "00000000    0000    "+fileName.substr(fileName.rfind(PATH_SEPARATOR)+1)+"\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
        iSymFile.write(outString.c_str(),outString.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
    reg.assign("Global Symbols");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
    while(aMap.getline(str,MAX_LINE)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
        if(regex_search(str, what, reg)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
            break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
    reg.assign("^\\s*(.+)\\s*0x(\\S+)\\s+[^\\d]*(\\d+)\\s+(.*)$");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
    string sSym,sTmp,sSection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
    unsigned int addr,size,baseOffset = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
    map<unsigned int,string> syms;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
    char symString[MAX_LINE];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
    while(aMap.getline(str,MAX_LINE)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
        if(regex_search(str, what, reg)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
            sSym.assign(what[1].first,what[1].second-what[1].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
            sTmp.assign(what[2].first,what[2].second-what[2].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
            addr = strtol(sTmp.c_str(), NULL, 16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
            sTmp.assign(what[3].first,what[3].second-what[3].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
            size = strtol(sTmp.c_str(), NULL, 10);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
            sSection.assign(what[4].first,what[4].second-what[4].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
            if(sSection.find("(StubCode)") != string::npos)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
                size = 8;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
            if(addr > 0) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
                memset(symString,0,sizeof(symString));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
                sprintf(symString,"%04x    ",size);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
                outString = symString;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
                outString += sSym+" ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
                outString += sSection;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
                if(baseOffset == 0) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
                    baseOffset = addr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
                unsigned int k = addr - baseOffset;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
                if( (syms.find(k) == syms.end()) || size != 0) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
                    syms[k] = outString;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
            }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
            // end of addr>0
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
        // end of regex_search
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
    map<unsigned int,string>::iterator it;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
    for(it = syms.begin(); it != syms.end(); it++) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
        memset(str,0,sizeof(str));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
        sprintf(str,"%08x",it->first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
        outString = str;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
        outString += "    ";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
        outString += it->second+"\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
        iSymFile.write(outString.c_str(),outString.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
void SymbolGenerator::ProcessGcceOrArm4File( const string& fileName, ifstream& aMap ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
    aMap.seekg (0, ios_base::beg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
    char str[MAX_LINE];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
    aMap.getline(str,MAX_LINE);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
    boost::cmatch what;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
    boost::regex reg("^\\.text\\s+");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
    while(aMap.getline(str,MAX_LINE)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
        if(regex_search(str, what, reg)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
            break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
    reg.assign("^\\.text\\s+(\\w+)\\s+\\w+");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
    if(!regex_search(str, what, reg)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
        printf("ERROR: Can't get .text section info for \"%s\"\n",fileName.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
    else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
        string sTmp, sLibFile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
        sTmp.assign(what[1].first,what[1].second-what[1].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
        unsigned int imgText = strtol(sTmp.c_str(), NULL, 16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
        reg.assign("^LONG 0x.*", boost::regex::icase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
        boost::cmatch what1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
        boost::regex reg1("^\\s(\\.text)?\\s+(0x\\w+)\\s+(0x\\w+)\\s+(.*)$", boost::regex::icase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
        boost::regex reg2("^\\s+(\\w+)\\s\\s+([a-zA-Z_].+)", boost::regex::icase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
        boost::regex reg3(".*lib\\(.*d\\d*s_?\\d{5}.o\\)$", boost::regex::icase);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
        map<unsigned int,string> syms;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
        unsigned int addr, len, stubhex;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
        while(aMap.getline(str,MAX_LINE)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
            if(strlen(str) == 0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
                break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
            else if(regex_search(str, what, reg1)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
                sLibFile.assign(what[4].first,what[4].second-what[4].first);
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
   205
                if(!regex_search(sLibFile.c_str(), what1, reg)) {
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
                    sTmp.assign(what[2].first,what[2].second-what[2].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
                    addr = strtol(sTmp.c_str(), NULL, 16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
                    sTmp.assign(what[3].first,what[3].second-what[3].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
                    len = strtol(sTmp.c_str(), NULL, 16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
                    syms[addr+len] = "";
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
   211
                    if(regex_search(sLibFile.c_str(), what, reg3)) {
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
                        stubhex = addr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
                    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
                }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
            }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
            else if(regex_search(str, what, reg2)) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
                sTmp.assign(what[1].first,what[1].second-what[1].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
                addr = strtol(sTmp.c_str(), NULL, 16);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
                sTmp.assign(what[2].first,what[2].second-what[2].first);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
                syms[addr] = (addr == stubhex)? ("stub "+sTmp) : sTmp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
            }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
        map<unsigned int,string>::iterator it = syms.begin();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
        map<unsigned int,string>::iterator itp = it++;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
        string outString;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
        for(; it != syms.end(); itp = it++) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
            if(itp->second != "") {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
                memset(str,0,sizeof(str));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
                sprintf(str,"%08x    %04x    ",(itp->first-imgText), (it->first-itp->first));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
                outString = str;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
                outString += it->second+"\n";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
                iSymFile.write(outString.c_str(),outString.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
            }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
        }
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
int SymbolGenerator::GetSizeFromBinFile( const string& fileName ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
    TInt ret = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
    ifstream aIf(fileName.c_str(), ios_base::binary);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
    if( !aIf.is_open() ) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
        printf("Warning: Cannot open file \n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
    else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
        E32ImageFile e32Image;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
        TUint32 aSz;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
        aIf.seekg(0,ios_base::end);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
        aSz = aIf.tellg();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
        e32Image.Adjust(aSz);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
        e32Image.iFileSize = aSz;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
        aIf.seekg(0,ios_base::beg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
        aIf >> e32Image;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
        ret = e32Image.iOrigHdr->iCodeSize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
    return ret;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
void SymbolGenerator::thrd_func(){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
    SymbolGenerator* me = GetInstance();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
    TPlacedEntry pe("",false);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
    while(1) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
        if(1) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
            //scope the code block with if(1) for lock
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
            boost::mutex::scoped_lock lock(me->iMutex);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
            while(me->iQueueFiles.empty())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
                me->iCond.wait(lock);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
            /*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
            if(me->iQueueFiles.empty()) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
                boost::this_thread::sleep(boost::posix_time::milliseconds(10));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
                continue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
            }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
            */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
            pe = me->iQueueFiles.front();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
            me->iQueueFiles.pop();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
        if(pe.iFileName == "")
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
            break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
        else if(pe.iExecutable) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
            me->ProcessExecutable(pe.iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
        else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
            me->ProcessDatafile(pe.iFileName);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
SymbolGenerator::SymbolGenerator() : boost::thread(thrd_func) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
SymbolGenerator::~SymbolGenerator(){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
    if(joinable())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
        join();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
    iSymFile.flush();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
    iSymFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
}