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

Last change on this file was 829, checked in by イグトランス (egtra), 13 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 4.7 KB
Line 
1#include "stdafx.h"
2
3#include "../../BasicCompiler_Common/DebugSection.h"
4
5//////////////////////////
6// ブレークポイント
7//////////////////////////
8
9BreakPointManager *pobj_DBBreakPoint;
10
11BreakPointsPerFile::BreakPointsPerFile(const char *lpszFileName,int iLineNum){
12 this->filename = lpszFileName;
13
14 lines.clear();
15 lines.push_back( iLineNum );
16}
17void BreakPointsPerFile::add(int iLineNum){
18 lines.push_back( iLineNum );
19}
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 }
29 }
30}
31
32void BreakPointsPerFile::update( char *nativeCodeBuffer, const SourceLines &sourceLines )
33{
34 int FileNum;
35 const IncludedFilesRelation *pIncludedFilesRelation = NULL;
36 const BasicSource *pNowSource = NULL;
37
38 extern BasicSources sourcesLinkRelationalObjectModule;
39 foreach( const BasicSource &source, sourcesLinkRelationalObjectModule )
40 {
41 pIncludedFilesRelation = &source.GetIncludedFilesRelation();
42
43 for(FileNum=0;FileNum<pIncludedFilesRelation->GetFileCounts();FileNum++)
44 {
45 if(lstrcmpi(pIncludedFilesRelation->GetFilePathFromFileNumber(FileNum).c_str(),this->filename.c_str())==0)
46 {
47 pNowSource = &source;
48 break;
49 }
50 }
51 if( FileNum == pIncludedFilesRelation->GetFileCounts() )
52 {
53 pIncludedFilesRelation = NULL;
54 }
55 else
56 {
57 break;
58 }
59 }
60
61 if( !pIncludedFilesRelation )
62 {
63 Jenga::Throw( "BreakPointsPerFile::update内で不正な処理" );
64 return;
65 }
66
67 int i;
68 for(i=0;;i++){
69 if( pIncludedFilesRelation->GetFileNumber( i ) == FileNum
70 || pIncludedFilesRelation->GetFileNumber( i ) == -1 )
71 {
72 break;
73 }
74 }
75 if( pIncludedFilesRelation->GetFileNumber( i ) == -1 )
76 {
77 return;
78 }
79
80 int FileBaseLine;
81 FileBaseLine=i;
82
83 int i2,nCount=0;
84 for(i2=0;;i2++){
85 if( pIncludedFilesRelation->GetFileNumber( FileBaseLine+i2 ) == -1 )
86 {
87 //ソースコードの終端行
88 break;
89 }
90
91 if(i2==this->lines[nCount]){
92loop:
93 int tempCp = GetSourceCodeIndexFromLine( pNowSource->GetBuffer(), FileBaseLine+i2 );
94
95 int i3;
96 for( i3=0; i3<static_cast<int>(sourceLines.size()-1); i3++ )
97 {
98 if( sourceLines[i3].GetSourceCodePosition().GetPos() == tempCp )
99 {
100 break;
101 }
102 }
103 if( i3 == sourceLines.size() - 1 )
104 {
105 i2--;
106 goto loop;
107 }
108
109 nativeCodeBuffer[sourceLines[i3].GetNativeCodePos()] = (char)0xCC;
110
111 nCount++;
112 if( nCount >= static_cast<int>(this->lines.size()) )
113 {
114 break;
115 }
116 }
117 }
118}
119
120
121BreakPointManager::BreakPointManager()
122{
123 char *buffer;
124 buffer=(char *)HeapAlloc(hHeap,0,65535);
125
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
131 HANDLE hFile=CreateFile(
132 temporary,
133 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
134 if(hFile!=INVALID_HANDLE_VALUE)
135 {
136 DWORD dwAccBytes;
137 ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL);
138 CloseHandle(hFile);
139 buffer[dwAccBytes]=0;
140 }
141 else
142 {
143 buffer[0]=0;
144 }
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 //行番号
155 char temporary[1024];
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}
169void BreakPointManager::insert(const char *lpszFileName,int iLineNum)
170{
171 BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles )
172 {
173 if(lstrcmpi(breakpointsPerFile.filename.c_str(),lpszFileName)==0)
174 {
175 breakpointsPerFile.add( iLineNum );
176 return;
177 }
178 }
179
180 this->breakpointsPerFiles.push_back( BreakPointsPerFile( lpszFileName, iLineNum ) );
181}
182void BreakPointManager::remove(const char *lpszFileName,int iLineNum)
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 }
194 break;
195 }
196 }
197}
198
199char *BreakPointManager::update( char *nativeCodeBuffer, int SizeOf_CodeSection, const SourceLines &sourceLines )
200{
201 char *buffer;
202 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
203 memcpy(buffer,nativeCodeBuffer,SizeOf_CodeSection);
204
205 BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles )
206 {
207 breakpointsPerFile.update( buffer, sourceLines );
208 }
209
210 return buffer;
211}
Note: See TracBrowser for help on using the repository browser.