1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | //////////////////////////
|
---|
4 | // ブレークポイント
|
---|
5 | //////////////////////////
|
---|
6 |
|
---|
7 | BreakPointManager *pobj_DBBreakPoint;
|
---|
8 |
|
---|
9 | BreakPointsPerFile::BreakPointsPerFile(const char *lpszFileName,int iLineNum){
|
---|
10 | this->filename = lpszFileName;
|
---|
11 |
|
---|
12 | lines.clear();
|
---|
13 | lines.push_back( iLineNum );
|
---|
14 | }
|
---|
15 | void BreakPointsPerFile::add(int iLineNum){
|
---|
16 | lines.push_back( iLineNum );
|
---|
17 | }
|
---|
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 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | void 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 |
|
---|
92 | loop:
|
---|
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 |
|
---|
116 | BreakPointManager::BreakPointManager()
|
---|
117 | {
|
---|
118 | char *buffer;
|
---|
119 | buffer=(char *)HeapAlloc(hHeap,0,65535);
|
---|
120 |
|
---|
121 | char temporary[MAX_PATH];
|
---|
122 | GetTempPath(MAX_PATH,temporary);
|
---|
123 | if(temporary[lstrlen(temporary)-1]!='\\') lstrcat(temporary,"\\");
|
---|
124 | lstrcat(temporary,"ab_breakpoint.tmp");
|
---|
125 |
|
---|
126 | HANDLE hFile=CreateFile(
|
---|
127 | temporary,
|
---|
128 | GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
|
---|
129 | if(hFile!=INVALID_HANDLE_VALUE)
|
---|
130 | {
|
---|
131 | DWORD dwAccBytes;
|
---|
132 | ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL);
|
---|
133 | CloseHandle(hFile);
|
---|
134 | buffer[dwAccBytes]=0;
|
---|
135 | }
|
---|
136 | else
|
---|
137 | {
|
---|
138 | buffer[0]=0;
|
---|
139 | }
|
---|
140 |
|
---|
141 | int i=0,i2;
|
---|
142 | char szFilePath[MAX_PATH];
|
---|
143 | while(buffer[i]){
|
---|
144 | //ファイルパス
|
---|
145 | i=GetOneParameter(buffer,i,szFilePath);
|
---|
146 | RemoveStringQuotes(szFilePath);
|
---|
147 |
|
---|
148 | while(buffer[i]!='\n'&&buffer[i]!='\0'){
|
---|
149 | //行番号
|
---|
150 | char temporary[1024];
|
---|
151 | i=GetOneParameter(buffer,i,temporary);
|
---|
152 | i2=atoi(temporary);
|
---|
153 |
|
---|
154 | insert(szFilePath,i2);
|
---|
155 | }
|
---|
156 |
|
---|
157 | while(buffer[i]=='\n') i++;
|
---|
158 |
|
---|
159 | if(buffer[i]=='\0') break;
|
---|
160 | }
|
---|
161 |
|
---|
162 | HeapDefaultFree(buffer);
|
---|
163 | }
|
---|
164 | void BreakPointManager::insert(const char *lpszFileName,int iLineNum)
|
---|
165 | {
|
---|
166 | BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles )
|
---|
167 | {
|
---|
168 | if(lstrcmpi(breakpointsPerFile.filename.c_str(),lpszFileName)==0)
|
---|
169 | {
|
---|
170 | breakpointsPerFile.add( iLineNum );
|
---|
171 | return;
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | this->breakpointsPerFiles.push_back( BreakPointsPerFile( lpszFileName, iLineNum ) );
|
---|
176 | }
|
---|
177 | void BreakPointManager::remove(const char *lpszFileName,int iLineNum)
|
---|
178 | {
|
---|
179 | for( int i=0; i<static_cast<int>(this->breakpointsPerFiles.size()); i++ )
|
---|
180 | {
|
---|
181 | BreakPointsPerFile *pBreakpointsPerFile = &breakpointsPerFiles[i];
|
---|
182 | if(lstrcmpi(pBreakpointsPerFile->filename.c_str(),lpszFileName)==0)
|
---|
183 | {
|
---|
184 | pBreakpointsPerFile->remove( iLineNum );
|
---|
185 | if( pBreakpointsPerFile->lines.empty() )
|
---|
186 | {
|
---|
187 | Jenga::Common::EraseVectorItem<BreakPointsPerFiles>( this->breakpointsPerFiles, i );
|
---|
188 | }
|
---|
189 | break;
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | char *BreakPointManager::update(char *nativeCodeBuffer,int SizeOf_CodeSection){
|
---|
195 | char *buffer;
|
---|
196 | buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
|
---|
197 | memcpy(buffer,nativeCodeBuffer,SizeOf_CodeSection);
|
---|
198 |
|
---|
199 | BOOST_FOREACH( BreakPointsPerFile &breakpointsPerFile, breakpointsPerFiles )
|
---|
200 | {
|
---|
201 | breakpointsPerFile.update( buffer );
|
---|
202 | }
|
---|
203 |
|
---|
204 | return buffer;
|
---|
205 | }
|
---|