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