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

Last change on this file since 650 was 648, checked in by dai_9181, 16 years ago

・ブレークポイントが正常に動作しない不具合を修正。
・と同時に、ブレークポイント周りのコードをリファクタリング

File size: 4.7 KB
Line 
1#include "stdafx.h"
2
3//////////////////////////
4// ブレークポイント
5//////////////////////////
6
7BreakPointManager *pobj_DBBreakPoint;
8
9BreakPointsPerFile::BreakPointsPerFile(char *lpszFileName,int iLineNum){
10 this->filename = lpszFileName;
11
12 lines.clear();
13 lines.push_back( iLineNum );
14}
15void BreakPointsPerFile::add(int iLineNum){
16 lines.push_back( iLineNum );
17}
18void 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 }
27 }
28}
29
30void BreakPointsPerFile::update(char *nativeCodeBuffer)
31{
32 int FileNum;
33 const IncludedFilesRelation *pIncludedFilesRelation = NULL;
34 const BasicSource *pNowSource = NULL;
35
36 extern BasicSources sourcesLinkRelationalObjectModule;
37 BOOST_FOREACH( const BasicSource &source, sourcesLinkRelationalObjectModule )
38 {
39 pIncludedFilesRelation = &source.GetIncludedFilesRelation();
40
41 for(FileNum=0;FileNum<pIncludedFilesRelation->GetFileCounts();FileNum++)
42 {
43 if(lstrcmpi(pIncludedFilesRelation->GetFilePathFromFileNumber(FileNum).c_str(),this->filename.c_str())==0)
44 {
45 pNowSource = &source;
46 break;
47 }
48 }
49 if( FileNum == pIncludedFilesRelation->GetFileCounts() )
50 {
51 pIncludedFilesRelation = NULL;
52 }
53 else
54 {
55 break;
56 }
57 }
58
59 if( !pIncludedFilesRelation )
60 {
61 Jenga::Throw( "BreakPointsPerFile::update内で不正な処理" );
62 return;
63 }
64
65 int i;
66 for(i=0;;i++){
67 if( pIncludedFilesRelation->GetFileNumber( i ) == FileNum
68 || pIncludedFilesRelation->GetFileNumber( i ) == -1 )
69 {
70 break;
71 }
72 }
73 if( pIncludedFilesRelation->GetFileNumber( i ) == -1 )
74 {
75 return;
76 }
77
78 int FileBaseLine;
79 FileBaseLine=i;
80
81 int i2,nCount=0;
82 for(i2=0;;i2++){
83 if( pIncludedFilesRelation->GetFileNumber( FileBaseLine+i2 ) == -1 )
84 {
85 //ソースコードの終端行
86 break;
87 }
88
89 if(i2==this->lines[nCount]){
90 extern SourceLines oldSourceLines;
91
92loop:
93 int tempCp = GetSourceCodeIndexFromLine( pNowSource->GetBuffer(), FileBaseLine+i2 );
94
95 int i3;
96 for(i3=0;i3<(int)oldSourceLines.size()-1;i3++){
97 if(oldSourceLines[i3].GetSourceCodePosition().GetPos()==tempCp) break;
98 }
99 if(i3==oldSourceLines.size()-1){
100 i2--;
101 goto loop;
102 }
103
104 nativeCodeBuffer[oldSourceLines[i3].GetNativeCodePos()]=(char)0xCC;
105
106 nCount++;
107 if( nCount >= static_cast<int>(this->lines.size()) )
108 {
109 break;
110 }
111 }
112 }
113}
114
115
116BreakPointManager::BreakPointManager()
117{
118 char *buffer;
119 buffer=(char *)HeapAlloc(hHeap,0,65535);
120
121 std::string filepath = ActiveBasic::Common::Environment::GetAbdevRootPath() + "\\ab_breakpoint.tmp";
122 HANDLE hFile=CreateFile(
123 filepath.c_str(),
124 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
125 if(hFile!=INVALID_HANDLE_VALUE)
126 {
127 DWORD dwAccBytes;
128 ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL);
129 CloseHandle(hFile);
130 buffer[dwAccBytes]=0;
131 }
132 else
133 {
134 buffer[0]=0;
135 }
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 //行番号
146 char temporary[1024];
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}
160void 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 );
167 return;
168 }
169 }
170
171 this->breakpointsPerFiles.push_back( BreakPointsPerFile( lpszFileName, iLineNum ) );
172}
173void 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 }
185 break;
186 }
187 }
188}
189
190char *BreakPointManager::update(char *nativeCodeBuffer,int SizeOf_CodeSection){
191 char *buffer;
192 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
193 memcpy(buffer,nativeCodeBuffer,SizeOf_CodeSection);
194
195 BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles )
196 {
197 breakpointsPerFile.update( buffer );
198 }
199
200 return buffer;
201}
Note: See TracBrowser for help on using the repository browser.