source: dev/BasicCompiler64/WatchList.cpp@ 47

Last change on this file since 47 was 40, checked in by dai_9181, 18 years ago

ByRef修飾子を関数戻り値とDimステートメントで指定可能にした。

File size: 12.1 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2#include "opcode.h"
3
4//デバッグ用
5#include "../BasicCompiler_Common/debug.h"
6
7int Debugging_GetArray(int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset);
8
9ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar){
10 extern DWORD ImageBase;
11 extern int MemPos_RWSection;
12 int i2;
13
14 if(pRelativeVar->dwKind==VAR_GLOBAL){
15 return ImageBase+MemPos_RWSection+pRelativeVar->offset;
16 }
17 else if(pRelativeVar->dwKind==VAR_LOCAL){
18 extern HWND hDebugWnd;
19 i2=(int)SendDlgItemMessage(hDebugWnd,IDC_PROCCOMBO,CB_GETCURSEL,0,0);
20 i2=pobj_dti->iProcLevel-i2;
21
22 if(pobj_dti->lplpSpBase[i2]==0) return 0;
23
24 return pobj_dti->lplpSpBase[i2]+pRelativeVar->offset;
25 }
26 else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
27 extern HWND hDebugWnd;
28 i2=(int)SendDlgItemMessage(hDebugWnd,IDC_PROCCOMBO,CB_GETCURSEL,0,0);
29 i2=pobj_dti->iProcLevel-i2;
30
31 if(pobj_dti->lplpSpBase[i2]==0) return 0;
32
33 extern HANDLE hDebugProcess;
34 LONG_PTR lpData;
35 SIZE_T stAccBytes;
36 ReadProcessMemory(hDebugProcess,
37 (void *)(pobj_dti->lplpSpBase[i2]+(int)pRelativeVar->offset),
38 &lpData,
39 sizeof(LONG_PTR),
40 &stAccBytes);
41
42 return lpData;
43 }
44 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
45 return pRelativeVar->offset;
46 }
47
48 return 0;
49}
50
51BOOL Debugging_SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){
52 int array_num;
53
54 _int64 i64data;
55 int type;
56 type=StaticCalculation(true, lpPtrOffset,0,&i64data,0,1);
57 if(!type) return 0;
58 if(IsRealNumberType(type)){
59 double dbl;
60 memcpy(&dbl,&i64data,sizeof(double));
61 i64data=(_int64)dbl;
62 }
63
64 array_num=(int)i64data;
65
66 if(PTR_LEVEL(*pType)){
67 *pType=MAKE_PTR_TYPE(NATURAL_TYPE(*pType),PTR_LEVEL(*pType)-1);
68 if((*pType)==DEF_OBJECT)
69 array_num*=GetSizeOfClassMember((CClass *)lpIndex,NULL,NULL);
70 else
71 array_num*=GetTypeSize(*pType,-1);
72 }
73 else{
74 //エラー
75 return 0;
76 }
77
78 extern HANDLE hDebugProcess;
79 LONG_PTR lpData;
80 SIZE_T stAccBytes;
81 lpData=Debugging_GetVarPtr(pRelativeVar);
82 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)) return 0;
83 pRelativeVar->dwKind=VAR_DIRECTMEM;
84
85 pRelativeVar->offset+=array_num;
86 return 1;
87}
88
89BOOL Debugging_GetMember(CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
90 int i,i2,offset;
91
92 //直接参照に切り替え
93 pRelativeVar->offset=(LONG_PTR)Debugging_GetVarPtr(pRelativeVar);
94 pRelativeVar->dwKind=VAR_DIRECTMEM;
95
96 //クラス、配列の構成要素を解析する
97 char VarName[VN_SIZE]; //変数名
98 char array[VN_SIZE]; //第1次配列
99 char lpPtrOffset[VN_SIZE]; //第2次配列
100 char NestMember[VN_SIZE]; //入れ子メンバ
101 int RefType; //"."参照のときは0、"->"参照のときは1
102 lstrcpy(VarName,member);
103 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,&RefType)) return 0;
104
105
106 ////////////////////////////
107 // メンバオフセットを取得
108 ////////////////////////////
109
110 offset=GetSizeOfClassMember(pobj_c,VarName,&i);
111 if(i==pobj_c->iMemberNum) return 0;
112
113
114 //アクセシビリティをチェック
115 if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
116 pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
117 return 0;
118 }
119 else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED)
120 return 0;
121
122 *pType=pobj_c->ppobj_Member[i]->TypeInfo.type;
123 *plpNestIndex=pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex;
124
125 //ポインタ変数の場合
126 if(IsPtrType(*pType)){
127 if(pobj_c->ppobj_Member[i]->SubScripts[0]==-1){
128 lstrcpy(lpPtrOffset,array);
129 array[0]=0;
130 }
131 }
132 else{
133 if(lpPtrOffset[0]) return 0;
134 }
135
136 pRelativeVar->offset+=offset;
137
138 if(array[0]){
139 //配列オフセット
140 i2=Debugging_GetArray(
141 pobj_c->ppobj_Member[i]->SubScripts,
142 array,
143 *pType,
144 pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex,
145 &pRelativeVar->offset);
146 if(i2==0){
147 //式エラー
148 return 0;
149 }
150 if(i2==-1){
151 //アクセスエラー
152 return -1;
153 }
154 }
155 else if(pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){
156 *pType|=FLAG_PTR;
157 }
158
159 if(NestMember[0]){
160 //入れ子構造の場合
161
162 if(*pType==DEF_OBJECT){
163 if(RefType!=DEF_OBJECT) return 0;
164 }
165 else if(*pType==DEF_PTR_OBJECT){
166 //構造体ポインタ型メンバ変数
167
168 if(lpPtrOffset[0]){
169 if(RefType!=DEF_OBJECT) return 0;
170
171 //直接参照に切り替え
172 Debugging_SetRelativeOffset(pType,*plpNestIndex,pRelativeVar,lpPtrOffset);
173
174 lpPtrOffset[0]=0;
175 }
176 else{
177 if(RefType!=DEF_PTR_OBJECT) return 0;
178
179 extern HANDLE hDebugProcess;
180 LONG_PTR lpData;
181 SIZE_T stAccBytes;
182 lpData=Debugging_GetVarPtr(pRelativeVar);
183 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)) return -1;
184 pRelativeVar->dwKind=VAR_DIRECTMEM;
185 }
186 }
187
188 i2=Debugging_GetMember(pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
189 NestMember,
190 pType,
191 pRelativeVar,
192 plpNestIndex,
193 0);
194 if(i2==0){
195 //式エラー
196 return 0;
197 }
198 if(i2==-1){
199 //アクセスエラー
200 return -1;
201 }
202 }
203
204 if(lpPtrOffset[0]){
205 Debugging_SetRelativeOffset(pType,*plpNestIndex,pRelativeVar,lpPtrOffset);
206 }
207
208 return 1;
209}
210int Debugging_GetArray(int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset){
211 extern HANDLE hHeap;
212 int i,i2,i3,i4,i5,array_offset,TypeSize;
213 char temporary[VN_SIZE],*pParm[MAX_PARMS];
214
215 for(i=0,i2=0,i3=0;;i++,i2++){
216 if(array[i]=='('){
217 i4=GetStringInPare(temporary+i2,array+i);
218 i+=i4-1;
219 i2+=i4-1;
220 continue;
221 }
222 if(array[i]=='['){
223 i4=GetStringInBracket(temporary+i2,array+i);
224 i+=i4-1;
225 i2+=i4-1;
226 continue;
227 }
228 if(array[i]==','||array[i]=='\0'){
229 if(SubScripts[i3]==-1){
230 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
231 return 0;
232 }
233
234 temporary[i2]=0;
235
236 pParm[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
237 lstrcpy(pParm[i3],temporary);
238
239 i3++;
240
241 if(array[i]=='\0'){
242 if(SubScripts[i3]!=-1){
243 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
244 return 0;
245 }
246 break;
247 }
248
249 i2=-1;
250 continue;
251 }
252 temporary[i2]=array[i];
253 }
254
255 array_offset=0;
256
257 for(i=i3-1;i>=0;i--){
258 _int64 i64data;
259 i2=StaticCalculation(true, pParm[i],0,&i64data,0,1);
260 if(i2==0){
261 //式エラー
262 return 0;
263 }
264 if(i2==-1){
265 //アクセスエラー
266 return -1;
267 }
268
269 if(IsRealNumberType(i2)){
270 double dbl;
271 memcpy(&dbl,&i64data,sizeof(double));
272 i64data=(_int64)dbl;
273 }
274 i5=(int)i64data;
275
276 for(i2=i+1,i4=1;i2<i3;i2++) i4*=SubScripts[i2]+1;
277
278 array_offset+=i5*i4;
279
280 HeapDefaultFree(pParm[i]);
281 }
282
283 TypeSize=GetTypeSize(type,lpIndex);
284
285 array_offset*=TypeSize;
286
287 *plpOffset+=array_offset;
288
289 return 1;
290}
291ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip){
292 int i;
293 SUBINFO *psi;
294
295 //ripからプロシージャを取得
296 psi=GetSubFromObp(obp_Rip);
297
298 for(i=0;i<psi->VarNum;i++){
299 if(lstrcmp(psi->pVar[i].name,"_System_LocalThis")==0) break;
300 }
301 if(i==psi->VarNum) return 0;
302
303 return psi->pVar[i].offset;
304}
305int Debugging_GetVarOffset(char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
306 extern HANDLE hDebugProcess;
307 int i,i2,i3,RefType;
308 char member[VN_SIZE],VarName[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];
309 LONG_PTR lpData;
310 SIZE_T stAccBytes;
311
312 lstrcpy(VarName,variable);
313 GetVarFormatString(VarName,array,lpPtrOffset,member,&RefType);
314
315 LONG_PTR lpIndex;
316 int *pSubScripts;
317 BOOL bArray;
318
319
320 /////////////////
321 // ローカル変数
322 /////////////////
323 extern VARIABLE *LocalVar;
324 extern int MaxLocalVarNum;
325 for(i=0;i<MaxLocalVarNum;i++){
326 if(lstrcmp(VarName,LocalVar[i].name)==0) break;
327 }
328 if(i!=MaxLocalVarNum){
329 //ポインタ変数の場合
330 if(IsPtrType(LocalVar[i].type)){
331 if(!LocalVar[i].bArray){
332 lstrcpy(lpPtrOffset,array);
333 array[0]=0;
334 }
335 }
336 else{
337 if(lpPtrOffset[0]) return 0;
338 }
339
340 pRelativeVar->offset=LocalVar[i].offset;
341 if(LocalVar[i].fRef) pRelativeVar->dwKind=VAR_REFLOCAL;
342 else pRelativeVar->dwKind=VAR_LOCAL;
343 *pType=LocalVar[i].type;
344 lpIndex=LocalVar[i].u.index;
345 *plpIndex=lpIndex;
346 bArray=LocalVar[i].bArray;
347 pSubScripts=LocalVar[i].SubScripts;
348 }
349 else{
350 if(pobj_CompilingClass){
351 ///////////////////////
352 // クラスメンバの参照
353 ///////////////////////
354
355 if(memicmp(variable,"This.",5)==0){
356 //Thisオブジェクトのメンバを参照するとき
357 SlideString(variable+5,-5);
358 lstrcpy(VarName,variable);
359 }
360 else{
361 //クラス内メンバを参照するとき(通常)
362
363 for(i=0;i<pobj_CompilingClass->iMemberNum;i++){
364 if(lstrcmp(VarName,pobj_CompilingClass->ppobj_Member[i]->name)==0) break;
365 }
366 if(i==pobj_CompilingClass->iMemberNum) goto NonClassMember;
367 }
368
369 /////////////////////////////
370 // thisポインタを取得
371
372 extern HWND hDebugWnd;
373 i2=(int)SendDlgItemMessage(hDebugWnd,IDC_PROCCOMBO,CB_GETCURSEL,0,0);
374 i2=pobj_dti->iProcLevel-i2;
375
376 lpData=Debugging_GetThisPtrOffset(pobj_dti->lplpObp[i2]);
377 if(!lpData){
378 //式エラー
379 return 0;
380 }
381 lpData+=pobj_dti->lplpSpBase[i2];
382 if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)){
383 //メモリにアクセスできないとき
384 return -1;
385 }
386
387 pRelativeVar->dwKind=VAR_DIRECTMEM;
388
389 LONG_PTR lp2;
390 i3=Debugging_GetMember(pobj_CompilingClass,variable,pType,pRelativeVar,&lp2,1);
391 if(i3==0){
392 //式エラー
393 return 0;
394 }
395 if(i3==-1){
396 //アクセスエラー
397 return -1;
398 }
399
400 *plpIndex=lp2;
401 return 1;
402 }
403
404NonClassMember:
405
406 ///////////////////
407 // グローバル変数
408 ///////////////////
409 extern VARIABLE *GlobalVar;
410 extern int MaxGlobalVarNum;
411
412 for(i=0;i<MaxGlobalVarNum;i++){
413 if(lstrcmp(VarName,GlobalVar[i].name)==0) break;
414 }
415 if(i==MaxGlobalVarNum){
416 //一致しないとき
417 return 0;
418 }
419
420 //ポインタ変数の場合
421 if(IsPtrType(GlobalVar[i].type)){
422 if(!GlobalVar[i].bArray){
423 lstrcpy(lpPtrOffset,array);
424 array[0]=0;
425 }
426 }
427 else{
428 if(lpPtrOffset[0]) return 0;
429 }
430
431 pRelativeVar->offset=GlobalVar[i].offset;
432 pRelativeVar->dwKind=VAR_GLOBAL;
433 *pType=GlobalVar[i].type;
434 lpIndex=GlobalVar[i].u.index;
435 *plpIndex=lpIndex;
436 bArray=GlobalVar[i].bArray;
437 pSubScripts=GlobalVar[i].SubScripts;
438 }
439
440
441 if(array[0]==0&&bArray){
442 //配列の先頭ポインタを示す場合
443 *pType|=FLAG_PTR;
444 if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM);
445 return 1;
446 }
447
448 if(array[0]){
449 i3=Debugging_GetArray(pSubScripts,array,*pType,lpIndex,&pRelativeVar->offset);
450 if(i3==0){
451 //式エラー
452 return 0;
453 }
454 if(i3==-1){
455 //アクセスエラー
456 return -1;
457 }
458 }
459 if(member[0]){
460 if(*pType==DEF_OBJECT){
461 //実態オブジェクトのメンバを参照(obj.member)
462 if(RefType!=DEF_OBJECT){
463 return 0;
464 }
465
466 LONG_PTR lp2;
467 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0);
468 if(i3==0){
469 //式エラー
470 return 0;
471 }
472 if(i3==-1){
473 //アクセスエラー
474 return -1;
475 }
476
477 *plpIndex=lp2;
478 }
479 else if(*pType==DEF_PTR_OBJECT){
480 //ポインタオブジェクトが示すメンバを参照
481 if(lpPtrOffset[0]){
482 //pObj[n].member
483 if(RefType!=DEF_OBJECT) return 0;
484 Debugging_SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset);
485
486 LONG_PTR lp2;
487 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0);
488 if(i3==0){
489 //式エラー
490 return 0;
491 }
492 if(i3==-1){
493 //アクセスエラー
494 return -1;
495 }
496
497 *plpIndex=lp2;
498 }
499 else{
500 //pObj->member
501 if(RefType!=DEF_PTR_OBJECT) return 0;
502
503 pRelativeVar->offset=Debugging_GetVarPtr(pRelativeVar);
504 pRelativeVar->dwKind=VAR_DIRECTMEM;
505
506 if(!ReadProcessMemory(hDebugProcess,(void *)pRelativeVar->offset,&lpData,sizeof(LONG_PTR),&stAccBytes)) return -1;
507 pRelativeVar->offset=lpData;
508
509 LONG_PTR lp2;
510 i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0);
511 if(i3==0){
512 //式エラー
513 return 0;
514 }
515 if(i3==-1){
516 //アクセスエラー
517 return -1;
518 }
519
520 *plpIndex=lp2;
521 }
522 }
523 else{
524 return 0;
525 }
526 return 1;
527 }
528
529 if(lpPtrOffset[0]){
530 if(!Debugging_SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset)) return 0;
531 }
532
533 return 1;
534}
Note: See TracBrowser for help on using the repository browser.