00001 #ifndef _LineInfoFinder_h_
00002 #define _LineInfoFinder_h_
00003
00004 #include <Base.h>
00005 #include <LineInfoTable.h>
00006 #include <SymbolTable.h>
00007
00008 #define C_FCN_BEGIN_NAME ".bf"
00009 #define C_FCN_END_NAME ".ef"
00010 #define CPP_FILE_FORWARD_OFFSET_TO_NAME 1
00011 #define CPP_GENERIC_FILE_SYM_NAME ".file"
00012 #define MAX_LINE_TEST 100
00013 #define MAX_LINE_VALUE 0x7fffffff
00014 #define FILE_TYPE_SOURCE 0
00015 #define FILE_TYPE_INCLUDE 1
00016
00017 #define GET_IS_INCL_FILE_BIT(i) ((isIncludeFile[i / (sizeof(uint16_t))] >> (i % sizeof(uint16_t))) & 0x0001)
00018 #define SET_IS_INCL_FILE_BIT(i) (isIncludeFile[i / (sizeof(uint16_t))] = isIncludeFile[i / (sizeof(uint16_t))] | (1 << (i % sizeof(uint16_t))))
00019 #define GET_IS_INCL_ADDR_BIT(i) ((isAddressFromIncludeFile[i / (sizeof(uint16_t))] >> (i % sizeof(uint16_t))) & 0x0001)
00020 #define SET_IS_INCL_ADDR_BIT(i) (isAddressFromIncludeFile[i / (sizeof(uint16_t))] = isAddressFromIncludeFile[i / (sizeof(uint16_t))] | (1 << (i % sizeof(uint16_t))))
00021
00022
00023 typedef struct idx_symndx {
00024 uint32_t index;
00025 uint32_t symndx;
00026 };
00027
00028 typedef struct idx_addr {
00029 uint32_t index;
00030 uint64_t address;
00031 };
00032
00033 int32_t compare_idx_addr(const void* a, const void* b);
00034
00035 class FileFinder;
00036
00037 class FunctionFinder : public Base {
00038 protected:
00039 char* functionName;
00040 uint32_t beginLineInfoIndex;
00041 uint32_t endLineInfoIndex;
00042 uint32_t firstLine;
00043 bool fromIncludeFile;
00044
00045 FileFinder* parentFile;
00046
00047 StringTable* stringTable;
00048 LineInfoTable* lineInfoTable;
00049 SymbolTable* symbolTable;
00050 public:
00051 FunctionFinder(SymbolTable* symTable, LineInfoTable* linTable, StringTable* strTable, uint32_t idx,
00052 struct idx_symndx* lineInfoFunctions, uint32_t numberOfLineInfoFunctions);
00053 ~FunctionFinder();
00054 FileFinder* setParent(FileFinder** files, uint32_t numberOfFiles);
00055 char* getName() { return functionName; }
00056 bool isFromIncludeFile() { return fromIncludeFile; }
00057 uint32_t getBeginLineInfoIndex() {return beginLineInfoIndex; }
00058 uint32_t getEndLineInfoIndex() { return endLineInfoIndex; }
00059 uint32_t getFirstLine() {return firstLine; }
00060 bool containsLineNumber(uint32_t lineno);
00061 FileFinder* getParentFile() { return parentFile; }
00062 uint64_t getAddressByLineNumber(uint32_t lineno);
00063 uint64_t getAddressByLineNumber(uint32_t lineno, uint64_t addr);
00064 void print();
00065 };
00066
00067
00068 class FileFinder : public Base {
00069 protected:
00070 char* fileName;
00071 uint32_t fileType;
00072 uint32_t symbolIndex;
00073 FunctionFinder** memberFunctions;
00074 uint32_t numberOfFunctions;
00075 bool includeFile;
00076
00077 StringTable* stringTable;
00078 LineInfoTable* lineInfoTable;
00079 SymbolTable* symbolTable;
00080 public:
00081 ~FileFinder() { delete memberFunctions; }
00082 char* getName() { return fileName; }
00083 uint32_t getSymbolIndex() { return symbolIndex;}
00084 uint32_t getFileType() { return fileType; }
00085 bool isIncludeFile() { return includeFile; }
00086 bool isSourceFile() { return !includeFile; }
00087 uint32_t setNumberOfFunctions(uint32_t numberFunctions);
00088 uint32_t addFunction(FunctionFinder* child, uint32_t idx);
00089
00090 virtual void print() { __SHOULD_NOT_ARRIVE; }
00091 virtual uint32_t getNumberOfFunctions() { __SHOULD_NOT_ARRIVE; return 0; }
00092 };
00093
00094 class IncludeFileFinder : public FileFinder {
00095 protected:
00096 FileFinder* parentFile;
00097 uint32_t lineInfoIndex;
00098 uint32_t endLineInfoIndex;
00099
00100 public:
00101 IncludeFileFinder(SymbolTable* symTable, LineInfoTable* linTable, StringTable* strTable, uint32_t idx, uint32_t linIndex, uint32_t endLinIndex);
00102 ~IncludeFileFinder();
00103 uint32_t getLineInfoIndex() { return lineInfoIndex; }
00104 uint32_t getEndLineInfoIndex() { return endLineInfoIndex; }
00105 FileFinder* getParentFile() { return parentFile; }
00106 bool containsAddress(uint64_t addr);
00107 void print();
00108 };
00109
00110
00111 class SourceFileFinder : public FileFinder {
00112 protected:
00113 uint32_t nameIndex;
00114 bool cppNameScheme;
00115
00116 public:
00117 SourceFileFinder(SymbolTable* symTable, LineInfoTable* linTable, StringTable* strTable, uint32_t idx);
00118 ~SourceFileFinder();
00119 bool containsLineNumber(uint32_t lineno);
00120 char* getName() { return fileName; }
00121 uint32_t getSymbolIndex() { return symbolIndex; }
00122 uint32_t getNameIndex() { return nameIndex; }
00123 bool isCppNameScheme() { return cppNameScheme; }
00124 uint32_t getNumberOfFunctions() { return numberOfFunctions; }
00125 void print();
00126 };
00127
00128
00129 class LineInfoFinder : public Base {
00130 protected:
00131 SymbolTable* symbolTable;
00132 StringTable* stringTable;
00133 uint64_t lineInfoPointer;
00134 LineInfoTable* lineInfoTable;
00135 bool is64Bit;
00136
00137
00138 LineInfo** lineInfos;
00139 uint32_t numberOfLineInfos;
00140 uint32_t* lineInfoLineNumbers;
00141 uint64_t* lineInfoAddresses;
00142 uint16_t* isIncludeFile;
00143 bool* isIncludeFile2;
00144 uint16_t* isAddressFromIncludeFile;
00145 bool* isAddressFromIncludeFile2;
00146 struct idx_addr* sortedAddresses;
00147 uint32_t numberOfLineAddresses;
00148 struct idx_symndx* lineInfoFunctions;
00149 uint32_t numberOfLineInfoFunctions;
00150
00151 uint32_t numberOfFiles;
00152 uint32_t numberOfFunctions;
00153 FileFinder** files;
00154 FunctionFinder** functions;
00155
00156 public:
00157 LineInfoFinder(uint32_t idx, XCoffFile* xCoffFile);
00158 ~LineInfoFinder();
00159
00160 uint32_t getLineInfoIndex(uint64_t fileOffset);
00161 uint32_t getLineInfoIndexOfAddr(uint64_t addr);
00162 uint32_t getLineInfoIndexOfPreviousAddr(uint64_t addr);
00163
00164 uint32_t getNumberOfFiles() { return numberOfFiles; }
00165 uint32_t getNumberOfFunctions() { return numberOfFunctions; }
00166
00167 uint32_t getLineNumberInFunction(uint64_t addr);
00168 uint32_t getLineNumberInFile(uint64_t addr);
00169
00170 bool isAddressInLineInfoTable(uint64_t addr);
00171 bool isFileNameInSymbolTable(char* fileName);
00172 bool isFunctionNameInSymbolTable(char* fcnName);
00173 bool functionContainsAddress(uint32_t idx, uint64_t addr);
00174
00175 char* getFileName(uint64_t addr);
00176 char* getFunctionName(uint64_t addr);
00177
00178 uint64_t getAddressByFile(uint32_t lineno, char* fileName);
00179 uint64_t getAddressByFunction(uint32_t lineno, char* fcnName);
00180 uint64_t getAddressByFile(uint32_t lineno, char* fileName, uint64_t addr);
00181 uint64_t getAddressByFunction(uint32_t lineno, char* fcnName, uint64_t addr);
00182
00183 bool isLineInFile(uint32_t lineno, char* fileName);
00184 bool isLineInFunction(uint32_t lineno, char* fcnName);
00185
00186 char* getFileNameOfFunction(char* fcnName);
00187
00188
00189
00190 void printFileSymbols();
00191 void printFiles();
00192 void printFunctions();
00193 void printSymbolTable();
00194 void printLineInfoTable();
00195 void printFunctionSymbols();
00196 bool testLineInfoFinder();
00197 void commandLineTest();
00198 };
00199
00200 #endif // _LineInfoFinder_h_