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

Last change on this file since 586 was 585, checked in by dai_9181, 17 years ago

NativeSectionクラスを追加(64bit版だけ一旦コミット)。

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