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

Last change on this file since 271 was 266, checked in by dai_9181, 17 years ago

BasicSourceのシリアライズがうまくいっていない

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