source: dev/BasicCompiler_Common/BreakPoint.cpp@ 6

Last change on this file since 6 was 4, checked in by dai_9181, 18 years ago
File size: 4.1 KB
RevLine 
[4]1#include "common.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 *OpBuffer){
40 extern INCLUDEFILEINFO IncludeFileInfo;
41
42 int FileNum;
43 for(FileNum=0;FileNum<IncludeFileInfo.FilesNum;FileNum++){
44 if(lstrcmpi(IncludeFileInfo.ppFileNames[FileNum],lpszFileName)==0) break;
45 }
46 if(FileNum==IncludeFileInfo.FilesNum) return;
47
48 int i;
49 for(i=0;;i++){
50 if(IncludeFileInfo.LineOfFile[i]==FileNum||
51 IncludeFileInfo.LineOfFile[i]==-1) break;
52 }
53 if(IncludeFileInfo.LineOfFile[i]==-1) return;
54
55 int FileBaseLine;
56 FileBaseLine=i;
57
58 int i2,nCount=0;
59 for(i2=0;;i2++){
60 if(IncludeFileInfo.LineOfFile[FileBaseLine+i2]==-1){
61 //ソースコードの終端行
62 break;
63 }
64
65 if(i2==piLine[nCount]){
66 extern int MaxLineInfoNum;
67 extern LINEINFO *pLineInfo;
68
69loop:
70 int tempCp;
71 tempCp=GetCpFromLine(FileBaseLine+i2);
72
73 int i3;
74 for(i3=0;i3<MaxLineInfoNum-1;i3++){
75 if(pLineInfo[i3].TopCp==tempCp) break;
76 }
77 if(i3==MaxLineInfoNum-1){
78 i2--;
79 goto loop;
80 }
81
82 OpBuffer[pLineInfo[i3].TopObp]=(char)0xCC;
83
84 nCount++;
85 if(nCount>=num) break;
86 }
87 }
88}
89
90
91CDBBreakPoint::CDBBreakPoint(){
92 ppItem=(CFileBreakPoint **)HeapAlloc(hHeap,0,1);
93 num=0;
94
95
96 HANDLE hFile;
97 char temporary[MAX_PATH];
98 GetTempPath(MAX_PATH,temporary);
99 if(temporary[lstrlen(temporary)-1]!='\\') lstrcat(temporary,"\\");
100 lstrcat(temporary,"ab_breakpoint.tmp");
101
102 //未完成
103 sprintf(temporary,"%sab_breakpoint.tmp",BasicSystemDir);
104
105 char *buffer;
106 buffer=(char *)HeapAlloc(hHeap,0,65535);
107
108 hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
109 if(hFile!=INVALID_HANDLE_VALUE){
110 DWORD dwAccBytes;
111 ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL);
112 CloseHandle(hFile);
113 buffer[dwAccBytes]=0;
114 }
115 else buffer[0]=0;
116
117 int i=0,i2;
118 char szFilePath[MAX_PATH];
119 while(buffer[i]){
120 //ファイルパス
121 i=GetOneParameter(buffer,i,szFilePath);
122 RemoveStringQuotes(szFilePath);
123
124 while(buffer[i]!='\n'&&buffer[i]!='\0'){
125 //行番号
126 i=GetOneParameter(buffer,i,temporary);
127 i2=atoi(temporary);
128
129 insert(szFilePath,i2);
130 }
131
132 while(buffer[i]=='\n') i++;
133
134 if(buffer[i]=='\0') break;
135 }
136
137 HeapDefaultFree(buffer);
138}
139CDBBreakPoint::~CDBBreakPoint(){
140 int i;
141 for(i=0;i<num;i++){
142 delete ppItem[i];
143 }
144 HeapDefaultFree(ppItem);
145}
146void CDBBreakPoint::insert(char *lpszFileName,int iLineNum){
147 int i;
148 for(i=0;i<num;i++){
149 if(lstrcmpi(ppItem[i]->lpszFileName,lpszFileName)==0){
150 ppItem[i]->add(iLineNum);
151 return;
152 }
153 }
154
155 if(i==num){
156 ppItem=(CFileBreakPoint **)HeapReAlloc(hHeap,0,ppItem,(num+1)*sizeof(CFileBreakPoint *));
157 ppItem[num]=new CFileBreakPoint(lpszFileName,iLineNum);
158 num++;
159 }
160}
161void CDBBreakPoint::remove(char *lpszFileName,int iLineNum){
162 int i;
163 for(i=0;i<num;i++){
164 if(lstrcmpi(lpszFileName,ppItem[i]->lpszFileName)==0){
165 ppItem[i]->remove(iLineNum);
166 break;
167 }
168 }
169 if(i==num) return;
170
171 if(ppItem[i]->num==0){
172 delete ppItem[i];
173
174 num--;
175 for(;i<num;i++){
176 ppItem[i]=ppItem[i+1];
177 }
178 }
179}
180
181char *CDBBreakPoint::update(char *OpBuffer,int SizeOf_CodeSection){
182 char *buffer;
183 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
184 memcpy(buffer,OpBuffer,SizeOf_CodeSection);
185
186 int i;
187 for(i=0;i<num;i++){
188 ppItem[i]->update(buffer);
189 }
190
191 return buffer;
192}
Note: See TracBrowser for help on using the repository browser.