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

Last change on this file since 482 was 313, checked in by dai_9181, 17 years ago

ステップ実行時の不正終了を回避

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