source: dev/trunk/abdev/BasicCompiler_Common/BreakPoint.cpp@ 307

Last change on this file since 307 was 280, checked in by dai_9181, 17 years ago
File size: 4.6 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 BOOST_FOREACH( const BasicSource &source, compiler.GetObjectModule().GetSources() )
51 {
52 pIncludedFilesRelation = &source.GetIncludedFilesRelation();
53
54 for(FileNum=0;FileNum<pIncludedFilesRelation->GetFileCounts();FileNum++)
55 {
56 if(lstrcmpi(pIncludedFilesRelation->GetFilePathFromFileNumber(FileNum).c_str(),lpszFileName)==0) break;
57 }
58 if( FileNum == pIncludedFilesRelation->GetFileCounts() )
59 {
60 pIncludedFilesRelation = NULL;
61 }
62 else
63 {
64 break;
65 }
66 }
67
68 if( !pIncludedFilesRelation )
69 {
70 Jenga::Throw( "CFileBreakPoint::update内で不正な処理" );
71 return;
72 }
73
74 int i;
75 for(i=0;;i++){
76 if( pIncludedFilesRelation->GetFileNumber( i ) == FileNum
77 || pIncludedFilesRelation->GetFileNumber( i ) == -1 )
78 {
79 break;
80 }
81 }
82 if( pIncludedFilesRelation->GetFileNumber( i ) == -1 )
83 {
84 return;
85 }
86
87 int FileBaseLine;
88 FileBaseLine=i;
89
90 int i2,nCount=0;
91 for(i2=0;;i2++){
92 if( pIncludedFilesRelation->GetFileNumber( FileBaseLine+i2 ) == -1 )
93 {
94 //ソースコードの終端行
95 break;
96 }
97
98 if(i2==piLine[nCount]){
99 extern SourceLines oldSourceLines;
100
101loop:
102 int tempCp;
103 tempCp=GetCpFromLine(FileBaseLine+i2);
104
105 int i3;
106 for(i3=0;i3<(int)oldSourceLines.size()-1;i3++){
107 if(oldSourceLines[i3].GetSourceCodePos()==tempCp) break;
108 }
109 if(i3==oldSourceLines.size()-1){
110 i2--;
111 goto loop;
112 }
113
114 nativeCodeBuffer[oldSourceLines[i3].GetNativeCodePos()]=(char)0xCC;
115
116 nCount++;
117 if(nCount>=num) break;
118 }
119 }
120}
121
122
123CDBBreakPoint::CDBBreakPoint(){
124 ppItem=(CFileBreakPoint **)HeapAlloc(hHeap,0,1);
125 num=0;
126
127 char *buffer;
128 buffer=(char *)HeapAlloc(hHeap,0,65535);
129
130 HANDLE hFile=CreateFile(
131 ( Jenga::Common::Environment::GetAppDir() + "\\ab_breakpoint.tmp" ).c_str(),
132 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
133 if(hFile!=INVALID_HANDLE_VALUE){
134 DWORD dwAccBytes;
135 ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL);
136 CloseHandle(hFile);
137 buffer[dwAccBytes]=0;
138 }
139 else buffer[0]=0;
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}
164CDBBreakPoint::~CDBBreakPoint(){
165 int i;
166 for(i=0;i<num;i++){
167 delete ppItem[i];
168 }
169 HeapDefaultFree(ppItem);
170}
171void CDBBreakPoint::insert(char *lpszFileName,int iLineNum){
172 int i;
173 for(i=0;i<num;i++){
174 if(lstrcmpi(ppItem[i]->lpszFileName,lpszFileName)==0){
175 ppItem[i]->add(iLineNum);
176 return;
177 }
178 }
179
180 if(i==num){
181 ppItem=(CFileBreakPoint **)HeapReAlloc(hHeap,0,ppItem,(num+1)*sizeof(CFileBreakPoint *));
182 ppItem[num]=new CFileBreakPoint(lpszFileName,iLineNum);
183 num++;
184 }
185}
186void CDBBreakPoint::remove(char *lpszFileName,int iLineNum){
187 int i;
188 for(i=0;i<num;i++){
189 if(lstrcmpi(lpszFileName,ppItem[i]->lpszFileName)==0){
190 ppItem[i]->remove(iLineNum);
191 break;
192 }
193 }
194 if(i==num) return;
195
196 if(ppItem[i]->num==0){
197 delete ppItem[i];
198
199 num--;
200 for(;i<num;i++){
201 ppItem[i]=ppItem[i+1];
202 }
203 }
204}
205
206char *CDBBreakPoint::update(char *nativeCodeBuffer,int SizeOf_CodeSection){
207 char *buffer;
208 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
209 memcpy(buffer,nativeCodeBuffer,SizeOf_CodeSection);
210
211 int i;
212 for(i=0;i<num;i++){
213 ppItem[i]->update(buffer);
214 }
215
216 return buffer;
217}
Note: See TracBrowser for help on using the repository browser.