source: dev/BasicCompiler32/WatchList.cpp@ 74

Last change on this file since 74 was 73, checked in by dai_9181, 18 years ago

Parameterクラスを適用。32bit側は動くようになったので、64bitのほうを調整する。

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