source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/BreakPoint.cpp@ 743

Last change on this file since 743 was 743, checked in by dai, 16 years ago

oldSourceLinesを排除。

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