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