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

Last change on this file since 611 was 603, checked in by dai_9181, 17 years ago

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

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