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

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