[206] | 1 | #include "stdafx.h" |
---|
| 2 | |
---|
[4] | 3 | ////////////////////////// |
---|
| 4 | // ブレークポイント |
---|
| 5 | ////////////////////////// |
---|
| 6 | |
---|
[648] | 7 | BreakPointManager *pobj_DBBreakPoint; |
---|
[4] | 8 | |
---|
[648] | 9 | BreakPointsPerFile::BreakPointsPerFile(char *lpszFileName,int iLineNum){ |
---|
| 10 | this->filename = lpszFileName; |
---|
[4] | 11 | |
---|
[648] | 12 | lines.clear(); |
---|
| 13 | lines.push_back( iLineNum ); |
---|
[4] | 14 | } |
---|
[648] | 15 | void BreakPointsPerFile::add(int iLineNum){ |
---|
| 16 | lines.push_back( iLineNum ); |
---|
[4] | 17 | } |
---|
[648] | 18 | void BreakPointsPerFile::remove( int iLineNum ) |
---|
| 19 | { |
---|
| 20 | for( int i=0; i<static_cast<int>(this->lines.size()); i++ ) |
---|
| 21 | { |
---|
| 22 | if( iLineNum == this->lines[i] ) |
---|
| 23 | { |
---|
| 24 | Jenga::Common::EraseVectorItem<std::vector<int>>( this->lines, i ); |
---|
| 25 | break; |
---|
| 26 | } |
---|
[4] | 27 | } |
---|
| 28 | } |
---|
| 29 | |
---|
[648] | 30 | void BreakPointsPerFile::update(char *nativeCodeBuffer) |
---|
[280] | 31 | { |
---|
[4] | 32 | int FileNum; |
---|
[280] | 33 | const IncludedFilesRelation *pIncludedFilesRelation = NULL; |
---|
[313] | 34 | const BasicSource *pNowSource = NULL; |
---|
[648] | 35 | |
---|
| 36 | extern BasicSources sourcesLinkRelationalObjectModule; |
---|
| 37 | BOOST_FOREACH( const BasicSource &source, sourcesLinkRelationalObjectModule ) |
---|
[280] | 38 | { |
---|
[648] | 39 | pIncludedFilesRelation = &source.GetIncludedFilesRelation(); |
---|
[280] | 40 | |
---|
| 41 | for(FileNum=0;FileNum<pIncludedFilesRelation->GetFileCounts();FileNum++) |
---|
| 42 | { |
---|
[648] | 43 | if(lstrcmpi(pIncludedFilesRelation->GetFilePathFromFileNumber(FileNum).c_str(),this->filename.c_str())==0) |
---|
[313] | 44 | { |
---|
[648] | 45 | pNowSource = &source; |
---|
[313] | 46 | break; |
---|
| 47 | } |
---|
[280] | 48 | } |
---|
| 49 | if( FileNum == pIncludedFilesRelation->GetFileCounts() ) |
---|
| 50 | { |
---|
| 51 | pIncludedFilesRelation = NULL; |
---|
| 52 | } |
---|
| 53 | else |
---|
| 54 | { |
---|
| 55 | break; |
---|
| 56 | } |
---|
[4] | 57 | } |
---|
[280] | 58 | |
---|
| 59 | if( !pIncludedFilesRelation ) |
---|
[279] | 60 | { |
---|
[648] | 61 | Jenga::Throw( "BreakPointsPerFile::update内で不正な処理" ); |
---|
[279] | 62 | return; |
---|
| 63 | } |
---|
[4] | 64 | |
---|
| 65 | int i; |
---|
| 66 | for(i=0;;i++){ |
---|
[280] | 67 | if( pIncludedFilesRelation->GetFileNumber( i ) == FileNum |
---|
| 68 | || pIncludedFilesRelation->GetFileNumber( i ) == -1 ) |
---|
[279] | 69 | { |
---|
| 70 | break; |
---|
| 71 | } |
---|
[4] | 72 | } |
---|
[280] | 73 | if( pIncludedFilesRelation->GetFileNumber( i ) == -1 ) |
---|
[279] | 74 | { |
---|
| 75 | return; |
---|
| 76 | } |
---|
[4] | 77 | |
---|
| 78 | int FileBaseLine; |
---|
| 79 | FileBaseLine=i; |
---|
| 80 | |
---|
| 81 | int i2,nCount=0; |
---|
| 82 | for(i2=0;;i2++){ |
---|
[280] | 83 | if( pIncludedFilesRelation->GetFileNumber( FileBaseLine+i2 ) == -1 ) |
---|
[279] | 84 | { |
---|
[4] | 85 | //ソースコードの終端行 |
---|
| 86 | break; |
---|
| 87 | } |
---|
| 88 | |
---|
[648] | 89 | if(i2==this->lines[nCount]){ |
---|
[263] | 90 | extern SourceLines oldSourceLines; |
---|
[4] | 91 | |
---|
| 92 | loop: |
---|
[313] | 93 | int tempCp = GetSourceCodeIndexFromLine( pNowSource->GetBuffer(), FileBaseLine+i2 ); |
---|
[4] | 94 | |
---|
| 95 | int i3; |
---|
[263] | 96 | for(i3=0;i3<(int)oldSourceLines.size()-1;i3++){ |
---|
[637] | 97 | if(oldSourceLines[i3].GetSourceCodePosition().GetPos()==tempCp) break; |
---|
[4] | 98 | } |
---|
[263] | 99 | if(i3==oldSourceLines.size()-1){ |
---|
[4] | 100 | i2--; |
---|
| 101 | goto loop; |
---|
| 102 | } |
---|
| 103 | |
---|
[263] | 104 | nativeCodeBuffer[oldSourceLines[i3].GetNativeCodePos()]=(char)0xCC; |
---|
[4] | 105 | |
---|
| 106 | nCount++; |
---|
[648] | 107 | if( nCount >= static_cast<int>(this->lines.size()) ) |
---|
| 108 | { |
---|
| 109 | break; |
---|
| 110 | } |
---|
[4] | 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
[648] | 116 | BreakPointManager::BreakPointManager() |
---|
| 117 | { |
---|
[4] | 118 | char *buffer; |
---|
| 119 | buffer=(char *)HeapAlloc(hHeap,0,65535); |
---|
| 120 | |
---|
[648] | 121 | std::string filepath = ActiveBasic::Common::Environment::GetAbdevRootPath() + "\\ab_breakpoint.tmp"; |
---|
[165] | 122 | HANDLE hFile=CreateFile( |
---|
[648] | 123 | filepath.c_str(), |
---|
[165] | 124 | GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); |
---|
[648] | 125 | if(hFile!=INVALID_HANDLE_VALUE) |
---|
| 126 | { |
---|
[4] | 127 | DWORD dwAccBytes; |
---|
| 128 | ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL); |
---|
| 129 | CloseHandle(hFile); |
---|
| 130 | buffer[dwAccBytes]=0; |
---|
| 131 | } |
---|
[648] | 132 | else |
---|
| 133 | { |
---|
| 134 | buffer[0]=0; |
---|
| 135 | } |
---|
[4] | 136 | |
---|
| 137 | int i=0,i2; |
---|
| 138 | char szFilePath[MAX_PATH]; |
---|
| 139 | while(buffer[i]){ |
---|
| 140 | //ファイルパス |
---|
| 141 | i=GetOneParameter(buffer,i,szFilePath); |
---|
| 142 | RemoveStringQuotes(szFilePath); |
---|
| 143 | |
---|
| 144 | while(buffer[i]!='\n'&&buffer[i]!='\0'){ |
---|
| 145 | //行番号 |
---|
[165] | 146 | char temporary[1024]; |
---|
[4] | 147 | i=GetOneParameter(buffer,i,temporary); |
---|
| 148 | i2=atoi(temporary); |
---|
| 149 | |
---|
| 150 | insert(szFilePath,i2); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | while(buffer[i]=='\n') i++; |
---|
| 154 | |
---|
| 155 | if(buffer[i]=='\0') break; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | HeapDefaultFree(buffer); |
---|
| 159 | } |
---|
[648] | 160 | void BreakPointManager::insert(char *lpszFileName,int iLineNum) |
---|
| 161 | { |
---|
| 162 | BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles ) |
---|
| 163 | { |
---|
| 164 | if(lstrcmpi(breakpointsPerFile.filename.c_str(),lpszFileName)==0) |
---|
| 165 | { |
---|
| 166 | breakpointsPerFile.add( iLineNum ); |
---|
[4] | 167 | return; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
[648] | 171 | this->breakpointsPerFiles.push_back( BreakPointsPerFile( lpszFileName, iLineNum ) ); |
---|
[4] | 172 | } |
---|
[648] | 173 | void BreakPointManager::remove(char *lpszFileName,int iLineNum) |
---|
| 174 | { |
---|
| 175 | for( int i=0; i<static_cast<int>(this->breakpointsPerFiles.size()); i++ ) |
---|
| 176 | { |
---|
| 177 | BreakPointsPerFile *pBreakpointsPerFile = &breakpointsPerFiles[i]; |
---|
| 178 | if(lstrcmpi(pBreakpointsPerFile->filename.c_str(),lpszFileName)==0) |
---|
| 179 | { |
---|
| 180 | pBreakpointsPerFile->remove( iLineNum ); |
---|
| 181 | if( pBreakpointsPerFile->lines.empty() ) |
---|
| 182 | { |
---|
| 183 | Jenga::Common::EraseVectorItem<BreakPointsPerFiles>( this->breakpointsPerFiles, i ); |
---|
| 184 | } |
---|
[4] | 185 | break; |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
[648] | 190 | char *BreakPointManager::update(char *nativeCodeBuffer,int SizeOf_CodeSection){ |
---|
[4] | 191 | char *buffer; |
---|
| 192 | buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection); |
---|
[256] | 193 | memcpy(buffer,nativeCodeBuffer,SizeOf_CodeSection); |
---|
[4] | 194 | |
---|
[648] | 195 | BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles ) |
---|
| 196 | { |
---|
| 197 | breakpointsPerFile.update( buffer ); |
---|
[4] | 198 | } |
---|
| 199 | |
---|
| 200 | return buffer; |
---|
| 201 | } |
---|