source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 73

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

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

File size: 25.2 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
6#include "../BasicCompiler32/opcode.h"
7#endif
8
9#define MDLFILE_VER 0x70000003
10
11
12void SetLpIndex_DebugFile(char *buffer,int *p,int type,LONG_PTR lpIndex){
13 if(NATURAL_TYPE(type)==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){
14 lstrcpy(buffer+(*p),((CClass *)lpIndex)->name);
15 (*p)+=lstrlen(buffer+(*p))+1;
16 }
17 else{
18 *(LONG_PTR *)(buffer+(*p))=lpIndex;
19 (*p)+=sizeof(LONG_PTR);
20 }
21}
22
23
24void GetLpIndex_DebugFile(char *buffer,int *p,int type,LONG_PTR *plpIndex){
25 if(NATURAL_TYPE(type)==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){
26 char szClassName[VN_SIZE];
27 lstrcpy(szClassName,buffer+(*p));
28 (*p)+=lstrlen(buffer+(*p))+1;
29
30 *plpIndex=(LONG_PTR)pobj_DBClass->check(szClassName);
31 }
32 else{
33 *plpIndex=*(LONG_PTR *)(buffer+(*p));
34 (*p)+=sizeof(LONG_PTR);
35 }
36}
37
38
39
40CDebugSection::CDebugSection(){
41 memset(this,0,sizeof(CDebugSection));
42}
43CDebugSection::~CDebugSection(){
44 if(pobj_DBClass) DeleteDebugInfo();
45 if(buffer){
46 HeapDefaultFree(buffer);
47 buffer=0;
48 }
49}
50void CDebugSection::make(void){
51 extern VARIABLE *GlobalVar;
52 extern int MaxGlobalVarNum;
53 extern INCLUDEFILEINFO IncludeFileInfo;
54 int i2,i3,i4,i5,BufferSize;
55
56 if(buffer){
57 HeapDefaultFree(buffer);
58 buffer=0;
59 }
60
61 i2=0;
62
63 extern char *basbuf;
64 i3=lstrlen(basbuf);
65
66 BufferSize=lstrlen(basbuf)+65535;
67 buffer=(char *)HeapAlloc(hHeap,0,BufferSize);
68
69 //デバッグ用ファイルのバージョン
70 *(long *)(buffer+i2)=MDLFILE_VER;
71 i2+=sizeof(long);
72
73 //プラットフォームのビット数
74 *(long *)(buffer+i2)=PLATFORM;
75 i2+=sizeof(long);
76
77 //インクルード情報
78 *(long *)(buffer+i2)=IncludeFileInfo.FilesNum;
79 i2+=sizeof(long);
80 for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
81 lstrcpy(buffer+i2,IncludeFileInfo.ppFileNames[i3]);
82 i2+=lstrlen(buffer+i2)+1;
83 }
84 buffer[i2++]=0;
85 for(i3=0;;i3++){
86 buffer[i2++]=(char)IncludeFileInfo.LineOfFile[i3];
87 if(IncludeFileInfo.LineOfFile[i3]==-1) break;
88 }
89
90 //ソースコード
91 lstrcpy(buffer+i2,basbuf);
92 i2+=lstrlen(buffer+i2)+1;
93
94
95 ////////////////////////
96 // コードと行番号の関係
97 ////////////////////////
98 extern int MaxLineInfoNum;
99 extern LINEINFO *pLineInfo;
100
101 //バッファが足りない場合は再確保
102 if(MaxLineInfoNum*sizeof(LINEINFO)<32768) i3=32768;
103 else i3=MaxLineInfoNum*sizeof(LINEINFO)+32768;
104 if(BufferSize<i2+i3){
105 BufferSize+=i3;
106 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
107 }
108
109 *(long *)(buffer+i2)=MaxLineInfoNum;
110 i2+=sizeof(long);
111 memcpy(buffer+i2,pLineInfo,MaxLineInfoNum*sizeof(LINEINFO));
112 i2+=MaxLineInfoNum*sizeof(LINEINFO);
113
114
115
116 ////////////////////////////////////////////
117 // クラス情報(名前のみ。詳細は後で保存)
118 ////////////////////////////////////////////
119
120 //イテレータをリセット
121 extern CDBClass *pobj_DBClass;
122 pobj_DBClass->Iterator_Reset();
123
124 //個数
125 *(long *)(buffer+i2)=pobj_DBClass->Iterator_GetMaxCount();
126 i2+=sizeof(long);
127
128 while(pobj_DBClass->Iterator_HasNext()){
129 CClass *pobj_c;
130 pobj_c=pobj_DBClass->Iterator_GetNext();
131
132 //クラス名
133 lstrcpy(buffer+i2,pobj_c->name);
134 i2+=lstrlen(buffer+i2)+1;
135 }
136
137
138
139 //////////////////
140 // TypeDef情報
141 //////////////////
142
143 extern CDBTypeDef *pobj_DBTypeDef;
144 *(long *)(buffer+i2)=pobj_DBTypeDef->iNum;
145 i2+=sizeof(long);
146 for(i3=0;i3<pobj_DBTypeDef->iNum;i3++){
147 lstrcpy(buffer+i2,pobj_DBTypeDef->ppobj_TypeDef[i3]->lpszName);
148 i2+=lstrlen(buffer+i2)+1;
149
150 lstrcpy(buffer+i2,pobj_DBTypeDef->ppobj_TypeDef[i3]->lpszBaseName);
151 i2+=lstrlen(buffer+i2)+1;
152
153 //バッファが足りない場合は再確保
154 if(BufferSize<i2+32768){
155 BufferSize+=32768;
156 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
157 }
158 }
159
160
161 //グローバル変数情報
162 *(long *)(buffer+i2)=MaxGlobalVarNum;
163 i2+=sizeof(long);
164 for(i3=0;i3<MaxGlobalVarNum;i3++){
165 VARIABLE *pVar=&GlobalVar[i3];
166
167 //変数名
168 lstrcpy(buffer+i2,pVar->name);
169 i2+=lstrlen(buffer+i2)+1;
170
171 //型
172 *(long *)(buffer+i2)=pVar->type;
173 i2+=sizeof(long);
174
175 //型の拡張情報
176 SetLpIndex_DebugFile(buffer,&i2,pVar->type,pVar->u.index);
177
178 buffer[i2++]=(char)pVar->fRef;
179
180 buffer[i2++]=(char)pVar->bArray;
181
182 if(pVar->bArray){
183 for(i4=0;;i4++){
184 *(long *)(buffer+i2)=pVar->SubScripts[i4];
185 i2+=sizeof(long);
186 if(pVar->SubScripts[i4]==-1) break;
187 }
188 }
189
190 //レキシカルスコープ情報
191 *(long *)(buffer+i2)=pVar->ScopeStartAddress;
192 i2+=sizeof(long);
193 *(long *)(buffer+i2)=pVar->ScopeEndAddress;
194 i2+=sizeof(long);
195 *(long *)(buffer+i2)=pVar->ScopeLevel;
196 i2+=sizeof(long);
197
198 //メモリ位置
199 *(long *)(buffer+i2)=pVar->offset;
200 i2+=sizeof(long);
201
202 //バッファが足りない場合は再確保
203 if(BufferSize<i2+32768){
204 BufferSize+=32768;
205 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
206 }
207 }
208
209 //グローバル実行領域のサイズ
210 extern int GlobalOpBufferSize;
211 *(long *)(buffer+i2)=GlobalOpBufferSize;
212 i2+=sizeof(long);
213
214 //プロシージャ情報
215 extern SubInfo **ppSubHash;
216 extern int SubNum;
217 SubInfo *psi;
218 *(long *)(buffer+i2)=SubNum;
219 i2+=sizeof(long);
220 for(i3=0;i3<MAX_HASH;i3++){
221 psi=ppSubHash[i3];
222 while(psi){
223 if(psi->pobj_ParentClass){
224 lstrcpy(buffer+i2,psi->pobj_ParentClass->name);
225 i2+=lstrlen(buffer+i2)+1;
226 }
227 else{
228 lstrcpy(buffer+i2,"");
229 i2+=lstrlen(buffer+i2)+1;
230 }
231
232 //ID
233 *(long *)(buffer+i2)=psi->id;
234 i2+=sizeof(long);
235
236 //関数名
237 lstrcpy(buffer+i2,psi->name);
238 i2+=lstrlen(buffer+i2)+1;
239
240 *(long *)(buffer+i2)=psi->CompileAddress;
241 i2+=sizeof(long);
242 *(long *)(buffer+i2)=psi->EndOpAddr;
243 i2+=sizeof(long);
244
245 *(long *)(buffer+i2)=psi->bVirtual;
246 i2+=sizeof(long);
247
248 //ローカル変数情報
249 *(long *)(buffer+i2)=psi->VarNum;
250 i2+=sizeof(long);
251
252 //バッファが足りない場合は再確保
253 if(BufferSize<i2+32768){
254 BufferSize+=32768;
255 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
256 }
257
258 for(i4=0;i4<psi->VarNum;i4++){
259 VARIABLE *pVar=&psi->pVar[i4];
260 lstrcpy(buffer+i2,pVar->name);
261 i2+=lstrlen(buffer+i2)+1;
262
263 //型
264 *(long *)(buffer+i2)=pVar->type;
265 i2+=sizeof(long);
266
267 //型の拡張情報
268 SetLpIndex_DebugFile(buffer,&i2,pVar->type,pVar->u.index);
269
270 //参照型パラメータかどうか
271 buffer[i2++]=(char)pVar->fRef;
272
273 //配列かどうか
274 buffer[i2++]=(char)pVar->bArray;
275
276 //配列要素
277 if(pVar->bArray){
278 for(i5=0;;i5++){
279 *(long *)(buffer+i2)=pVar->SubScripts[i5];
280 i2+=sizeof(long);
281 if(pVar->SubScripts[i5]==-1) break;
282 }
283 }
284 else pVar->SubScripts[0]=-1;
285
286 //レキシカルスコープ情報
287 *(long *)(buffer+i2)=pVar->ScopeStartAddress;
288 i2+=sizeof(long);
289 *(long *)(buffer+i2)=pVar->ScopeEndAddress;
290 i2+=sizeof(long);
291 *(long *)(buffer+i2)=pVar->ScopeLevel;
292 i2+=sizeof(long);
293
294 //メモリ位置
295 *(long *)(buffer+i2)=pVar->offset;
296 i2+=sizeof(long);
297
298
299
300
301 //バッファが足りない場合は再確保
302 if(BufferSize<i2+32768){
303 BufferSize+=32768;
304 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
305 }
306 }
307
308 psi=psi->pNextData;
309 }
310 }
311
312
313
314 ///////////////////
315 // クラス情報
316 ///////////////////
317
318 //イテレータをリセット
319 pobj_DBClass->Iterator_Reset();
320
321 while(pobj_DBClass->Iterator_HasNext()){
322 CClass *pobj_c;
323 pobj_c=pobj_DBClass->Iterator_GetNext();
324
325
326 //クラス名
327 lstrcpy(buffer+i2,pobj_c->name);
328 i2+=lstrlen(buffer+i2)+1;
329
330 //仮想関数の数
331 *(long *)(buffer+i2)=pobj_c->vtbl_num;
332 i2+=sizeof(long);
333
334 //アラインメント
335 *(long *)(buffer+i2)=pobj_c->iAlign;
336 i2+=sizeof(long);
337
338 //メンバ
339 *(long *)(buffer+i2)=pobj_c->iMemberNum;
340 i2+=sizeof(long);
341 for(i4=0;i4<pobj_c->iMemberNum;i4++){
342 lstrcpy(buffer+i2,pobj_c->ppobj_Member[i4]->name);
343 i2+=lstrlen(buffer+i2)+1;
344
345 memcpy(buffer+i2,pobj_c->ppobj_Member[i4]->SubScripts,sizeof(int)*MAX_ARRAYDIM);
346 i2+=sizeof(int)*MAX_ARRAYDIM;
347
348 //型
349 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->TypeInfo.type;
350 i2+=sizeof(long);
351
352 //型の拡張情報
353 SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
354
355 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->dwAccess;
356 i2+=sizeof(long);
357
358 //バッファが足りない場合は再確保
359 if(BufferSize<i2+32768){
360 BufferSize+=32768;
361 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
362 }
363 }
364
365 //メソッド
366 *(long *)(buffer+i2)=(long)pobj_c->methods.size();
367 i2+=sizeof(long);
368 foreach( CMethod *method, pobj_c->methods ){
369 *(long *)(buffer+i2)=method->dwAccess;
370 i2+=sizeof(long);
371 if(method->pobj_InheritsClass){
372 lstrcpy(buffer+i2,method->pobj_InheritsClass->name);
373 i2+=lstrlen(buffer+i2)+1;
374 }
375 else{
376 lstrcpy(buffer+i2,"");
377 i2+=lstrlen(buffer+i2)+1;
378 }
379 lstrcpy(buffer+i2,method->psi->name);
380 i2+=lstrlen(buffer+i2)+1;
381 }
382
383 //静的メンバ
384 *(long *)(buffer+i2)=(long)pobj_c->staticMembers.size();
385 i2+=sizeof(long);
386 foreach( CMember *member, pobj_c->staticMembers ){
387 lstrcpy(buffer+i2,member->name);
388 i2+=lstrlen(buffer+i2)+1;
389
390 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
391 i2+=sizeof(int)*MAX_ARRAYDIM;
392
393 //型
394 *(long *)(buffer+i2)=member->TypeInfo.type;
395 i2+=sizeof(long);
396
397 //型の拡張情報
398 SetLpIndex_DebugFile(buffer,&i2,member->TypeInfo.type,member->TypeInfo.u.lpIndex);
399
400 *(long *)(buffer+i2)=member->dwAccess;
401 i2+=sizeof(long);
402
403 //バッファが足りない場合は再確保
404 if(BufferSize<i2+32768){
405 BufferSize+=32768;
406 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
407 }
408 }
409
410 //バッファが足りない場合は再確保
411 if(BufferSize<i2+32768){
412 BufferSize+=32768;
413 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
414 }
415 }
416
417 length=i2;
418}
419
420char *CDebugSection::MakeSingleStepCode(void){
421 char *buffer;
422 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
423
424 memcpy(buffer,OpBuffer,SizeOf_CodeSection);
425
426 int i2;
427 for(i2=0;i2<MaxLineInfoNum;i2++){
428 if(!(
429 pLineInfo[i2].dwCodeType&CODETYPE_SYSTEMPROC||
430 pLineInfo[i2].dwCodeType&CODETYPE_DEBUGPROC
431 )){
432 //int 3
433 buffer[pLineInfo[i2].TopObp]=(char)0xCC;
434 }
435 }
436
437 return buffer;
438}
439BOOL CDebugSection::__load(void){
440 int i2,i3,i4,i5,num;
441 char temp2[MAX_PATH],*temp5;
442
443 extern CClass *pobj_CompilingClass;
444 pobj_CompilingClass=0;
445
446 i2=0;
447
448 //デバッグ用ファイルのバージョンをチェック
449 if(*(long *)(buffer+i2)<MDLFILE_VER){
450 HeapDefaultFree(buffer);
451 return 0;
452 }
453 i2+=sizeof(long);
454
455 //プラットフォームのビット数をチェック
456 if(*(long *)(buffer+i2)!=PLATFORM){
457 HeapDefaultFree(buffer);
458 return 0;
459 }
460 i2+=sizeof(long);
461
462 //インクルード情報
463 IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
464 i2+=sizeof(long);
465 IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *));
466 for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
467 if(buffer[i2]=='\0') break;
468 IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
469 lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2);
470 i2+=lstrlen(buffer+i2)+1;
471 }
472 for(i2++,i3=0;;i2++,i3++){
473 IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2];
474 if(IncludeFileInfo.LineOfFile[i3]==-1) break;
475 }
476
477 //ソースコード
478 i2++;
479 pBaseBuffer=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+3);
480 basbuf=pBaseBuffer+2;
481 lstrcpy(basbuf,buffer+i2);
482 i2+=lstrlen(buffer+i2)+1;
483 extern char *basbuf;
484 basbuf=this->basbuf;
485
486 //コードと行番号の関係
487 MaxLineInfoNum=*(long *)(buffer+i2);
488 i2+=sizeof(long);
489 pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1);
490 memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO));
491 i2+=MaxLineInfoNum*sizeof(LINEINFO);
492
493
494 ///////////////////////////////////////////
495 // クラス情報(名前のみ。詳細は後で取得)
496 ///////////////////////////////////////////
497
498 this->pobj_DBClass=new CDBClass();
499
500 int iMaxClassCount;
501 iMaxClassCount=*(long *)(buffer+i2);
502 i2+=sizeof(long);
503 for(i3=0;i3<iMaxClassCount;i3++){
504 //クラス名
505 pobj_DBClass->AddClass(buffer+i2,0);
506 i2+=lstrlen(buffer+i2)+1;
507 }
508
509 extern CDBClass *pobj_DBClass;
510 pobj_DBClass=this->pobj_DBClass;
511
512
513 //////////////////
514 // TypeDef情報
515 //////////////////
516
517 //初期化
518 pobj_DBTypeDef=new CDBTypeDef;
519
520 //個数を取得
521 num=*(long *)(buffer+i2);
522 i2+=sizeof(long);
523 for(i3=0;i3<num;i3++){
524 temp5=buffer+i2;
525 i2+=lstrlen(buffer+i2)+1;
526
527 pobj_DBTypeDef->add(temp5,buffer+i2);
528
529 i2+=lstrlen(buffer+i2)+1;
530 }
531
532 extern CDBTypeDef *pobj_DBTypeDef;
533 pobj_DBTypeDef=this->pobj_DBTypeDef;
534
535 //定数を取得
536 GetConstInfo();
537 extern CONSTINFO **ppConstHash;
538 this->ppConstHash=ppConstHash;
539
540
541 //グローバル変数情報
542 MaxGlobalVarNum=*(long *)(buffer+i2);
543 i2+=sizeof(long);
544 GlobalVar=(VARIABLE *)HeapAlloc(hHeap,0,MaxGlobalVarNum*sizeof(VARIABLE)+1);
545 for(i3=0;i3<MaxGlobalVarNum;i3++){
546 VARIABLE *pVar=&GlobalVar[i3];
547
548 //変数名
549 lstrcpy(pVar->name,buffer+i2);
550 i2+=lstrlen(buffer+i2)+1;
551
552 pVar->type=*(long *)(buffer+i2);
553 i2+=sizeof(long);
554
555 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
556
557 pVar->fRef=(long)buffer[i2++];
558
559 pVar->bArray=(long)buffer[i2++];
560 if(pVar->bArray){
561 for(i4=0;;i4++){
562 pVar->SubScripts[i4]=*(long *)(buffer+i2);
563 i2+=sizeof(long);
564
565 if(pVar->SubScripts[i4]==-1) break;
566 }
567 }
568
569 //レキシカルスコープ情報
570 pVar->ScopeStartAddress=*(long *)(buffer+i2);
571 i2+=sizeof(long);
572 pVar->ScopeEndAddress=*(long *)(buffer+i2);
573 i2+=sizeof(long);
574 pVar->ScopeLevel=*(long *)(buffer+i2);
575 i2+=sizeof(long);
576
577 //メモリ位置
578 pVar->offset=*(long *)(buffer+i2);
579 i2+=sizeof(long);
580 }
581
582 //グローバル実行領域のサイズ
583 GlobalOpBufferSize=*(long *)(buffer+i2);
584 i2+=sizeof(long);
585
586 //プロシージャ情報
587 SubInfo *psi;
588 SubNum=*(long *)(buffer+i2);
589 i2+=sizeof(long);
590 ppSubHash=(SubInfo **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SubInfo *));
591 for(i3=0;i3<SubNum;i3++){
592 psi = new SubInfo();
593 psi->pNextData=0;
594
595 char szParentClassName[VN_SIZE];
596 lstrcpy(szParentClassName,buffer+i2);
597 i2+=lstrlen(buffer+i2)+1;
598
599 if(szParentClassName[0])
600 psi->pobj_ParentClass=pobj_DBClass->check(szParentClassName);
601 else psi->pobj_ParentClass=0;
602
603 //ID
604 psi->id=*(long *)(buffer+i2);
605 i2+=sizeof(long);
606
607 //名前
608 psi->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
609 lstrcpy(psi->name,buffer+i2);
610 i2+=lstrlen(buffer+i2)+1;
611
612 psi->CompileAddress=*(long *)(buffer+i2);
613 i2+=sizeof(long);
614 psi->EndOpAddr=*(long *)(buffer+i2);
615 i2+=sizeof(long);
616
617 psi->bVirtual=*(long *)(buffer+i2);
618 i2+=sizeof(long);
619
620 psi->bCompile=1;
621
622 //ローカル変数情報
623 psi->VarNum=*(long *)(buffer+i2);
624 i2+=sizeof(long);
625 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,psi->VarNum*sizeof(VARIABLE)+1);
626 for(i4=0;i4<psi->VarNum;i4++){
627 VARIABLE *pVar=&psi->pVar[i4];
628
629 //ローカル変数名
630 lstrcpy(pVar->name,buffer+i2);
631 i2+=lstrlen(buffer+i2)+1;
632
633 //型
634 pVar->type=*(long *)(buffer+i2);
635 i2+=sizeof(long);
636
637 //型の拡張情報
638 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
639
640 //参照型パラメータかどうか
641 pVar->fRef=(long)buffer[i2++];
642
643 //配列かどうか
644 pVar->bArray=(long)buffer[i2++];
645 if(pVar->bArray){
646 for(i5=0;;i5++){
647 //配列要素
648 pVar->SubScripts[i5]=*(long *)(buffer+i2);
649 i2+=sizeof(long);
650
651 if(pVar->SubScripts[i5]==-1) break;
652 }
653 }
654
655 //レキシカルスコープ情報
656 pVar->ScopeStartAddress=*(long *)(buffer+i2);
657 i2+=sizeof(long);
658 pVar->ScopeEndAddress=*(long *)(buffer+i2);
659 i2+=sizeof(long);
660 pVar->ScopeLevel=*(long *)(buffer+i2);
661 i2+=sizeof(long);
662
663 //メモリ上の位置
664 pVar->offset=*(long *)(buffer+i2);
665 i2+=sizeof(long);
666 }
667
668
669 /////////////////////////////////
670 // 格納位置を計算してpsiをセット
671 /////////////////////////////////
672
673 i4=hash_default(psi->name);
674
675 SubInfo *psi2;
676 if(ppSubHash[i4]){
677 psi2=ppSubHash[i4];
678 while(1){
679 if(psi2->pNextData==0){
680 psi2->pNextData=psi;
681 break;
682 }
683 psi2=psi2->pNextData;
684 }
685 }
686 else{
687 ppSubHash[i4]=psi;
688 }
689 }
690
691 //クラス情報
692 CClass *pobj_c;
693 for(i3=0;i3<iMaxClassCount;i3++){
694 //クラス名
695 char szClassName[VN_SIZE];
696 lstrcpy(szClassName,buffer+i2);
697 i2+=lstrlen(buffer+i2)+1;
698
699 pobj_c=pobj_DBClass->check(szClassName);
700
701 //仮想関数の数
702 pobj_c->vtbl_num=*(long *)(buffer+i2);
703 i2+=sizeof(long);
704
705 //アラインメント
706 pobj_c->iAlign=*(long *)(buffer+i2);
707 i2+=sizeof(long);
708
709 //メンバ
710 pobj_c->iMemberNum=*(long *)(buffer+i2);
711 i2+=sizeof(long);
712 pobj_c->ppobj_Member=
713 (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *));
714 for(i4=0;i4<pobj_c->iMemberNum;i4++){
715 pobj_c->ppobj_Member[i4]=new CMember();
716
717 pobj_c->ppobj_Member[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
718 lstrcpy(pobj_c->ppobj_Member[i4]->name,buffer+i2);
719 i2+=lstrlen(buffer+i2)+1;
720
721 memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
722 i2+=sizeof(int)*MAX_ARRAYDIM;
723
724 //型
725 pobj_c->ppobj_Member[i4]->TypeInfo.type=*(long *)(buffer+i2);
726 i2+=sizeof(long);
727
728 //型の拡張情報
729 GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,&pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
730
731 pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2);
732 i2+=sizeof(long);
733 }
734
735 //メソッド
736 int nMethod = *(long *)(buffer+i2);
737 i2+=sizeof(long);
738 for( i4=0; i4<nMethod; i4++ ){
739 CMethod *method = new CMethod();
740
741 method->dwAccess=*(long *)(buffer+i2);
742 i2+=sizeof(long);
743
744 char szInherits[VN_SIZE];
745 lstrcpy(szInherits,buffer+i2);
746 i2+=lstrlen(buffer+i2)+1;
747
748 if(szInherits[0])
749 method->pobj_InheritsClass=pobj_DBClass->check(szInherits);
750 else method->pobj_InheritsClass=0;
751
752 lstrcpy(temp2,buffer+i2);
753 i2+=lstrlen(buffer+i2)+1;
754
755 CClass *pobj_temp_c;
756 pobj_temp_c=method->pobj_InheritsClass;
757 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
758 i5=hash_default(temp2);
759 psi=ppSubHash[i5];
760 while(1){
761 if(lstrcmp(psi->name,temp2)==0&&psi->pobj_ParentClass==pobj_temp_c) break;
762 psi=psi->pNextData;
763 }
764 method->psi=psi;
765
766 pobj_c->methods.push_back( method );
767 }
768
769 //静的メンバ
770 int nStaticMember = *(long *)(buffer+i2);
771 i2+=sizeof(long);
772 for( i4=0; i4<nStaticMember; i4++ ){
773 CMember *member=new CMember();
774
775 member->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
776 lstrcpy(member->name,buffer+i2);
777 i2+=lstrlen(buffer+i2)+1;
778
779 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
780 i2+=sizeof(int)*MAX_ARRAYDIM;
781
782 //型
783 member->TypeInfo.type=*(long *)(buffer+i2);
784 i2+=sizeof(long);
785
786 //型の拡張情報
787 GetLpIndex_DebugFile(buffer,&i2,member->TypeInfo.type,&member->TypeInfo.u.lpIndex);
788
789 member->dwAccess=*(long *)(buffer+i2);
790 i2+=sizeof(long);
791
792 pobj_c->staticMembers.push_back( member );
793 }
794 }
795
796 HeapDefaultFree(buffer);
797 buffer=0;
798
799
800
801
802 extern SubInfo **ppSubHash;
803 ppSubHash=this->ppSubHash;
804 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
805
806
807 SingleStepCodeBuffer=MakeSingleStepCode();
808
809
810 /////////////////////////////
811 // ブレークポイントを適用
812 /////////////////////////////
813
814 //インクルード情報
815 extern INCLUDEFILEINFO IncludeFileInfo;
816 IncludeFileInfo=this->IncludeFileInfo;
817
818 //コードと行番号の関係
819 extern int MaxLineInfoNum;
820 extern LINEINFO *pLineInfo;
821 MaxLineInfoNum=this->MaxLineInfoNum;
822 pLineInfo=this->pLineInfo;
823
824 BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
825
826 //プロセスメモリにコピー
827 extern HANDLE hDebugProcess;
828 SIZE_T stAccBytes;
829 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
830 BreakStepCodeBuffer,
831 SizeOf_CodeSection,&stAccBytes);
832
833
834 return 1;
835}
836
837BOOL CDebugSection::load(HMODULE hModule){
838 if(buffer){
839 HeapDefaultFree(buffer);
840 buffer=0;
841 }
842
843
844 extern HANDLE hDebugProcess;
845 SIZE_T stAccBytes;
846 IMAGE_DOS_HEADER ImageDosHeader;
847 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&stAccBytes);
848
849 int pe_size;
850#ifdef _AMD64_
851 IMAGE_NT_HEADERS64 pe_hdr;
852 pe_size=sizeof(IMAGE_NT_HEADERS64);
853#else
854 IMAGE_NT_HEADERS pe_hdr;
855 pe_size=sizeof(IMAGE_NT_HEADERS);
856#endif
857 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&stAccBytes);
858
859 IMAGE_SECTION_HEADER *pSectionHdr;
860 pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
861 ReadProcessMemory(hDebugProcess,
862 (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
863 pSectionHdr,
864 pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
865 &stAccBytes);
866
867 int i;
868 for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
869
870 //リライタブルセクション内の情報
871 if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
872 dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
873 }
874
875 //コードセクション内の情報
876 if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
877 dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
878 SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
879 }
880
881 //デバッグセクション内の情報
882 if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
883 length=pSectionHdr[i].Misc.VirtualSize;
884 buffer=(char *)HeapAlloc(hHeap,0,length+1);
885
886 ReadProcessMemory(hDebugProcess,
887 (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
888 buffer,
889 length,
890 &stAccBytes);
891 buffer[length]=0;
892 }
893
894 }
895 HeapDefaultFree(pSectionHdr);
896
897 if(!buffer) return 0;
898
899
900 dwImageBase=(DWORD)(ULONG_PTR)hModule;
901
902
903
904 if(OpBuffer) HeapDefaultFree(OpBuffer);
905 OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
906
907 ReadProcessMemory(hDebugProcess,
908 (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
909 SizeOf_CodeSection,&stAccBytes);
910
911
912 return __load();
913}
914
915void CDebugSection::choice(void){
916 //イメージベース
917 extern DWORD ImageBase;
918 ImageBase=this->dwImageBase;
919
920 //リライタブルセクションのRVA
921 extern int MemPos_RWSection;
922 MemPos_RWSection=this->dwRVA_RWSection;
923
924 //コードセクションのRVAとサイズ
925 extern int MemPos_CodeSection;
926 extern int FileSize_CodeSection;
927 MemPos_CodeSection=this->dwRVA_CodeSection;
928 FileSize_CodeSection=this->SizeOf_CodeSection;
929
930 //インクルード情報
931 extern INCLUDEFILEINFO IncludeFileInfo;
932 IncludeFileInfo=this->IncludeFileInfo;
933
934 //ソースコード
935 extern char *pBaseBuffer;
936 extern char *basbuf;
937 pBaseBuffer=this->pBaseBuffer;
938 basbuf=this->basbuf;
939
940 //コードと行番号の関係
941 extern int MaxLineInfoNum;
942 extern LINEINFO *pLineInfo;
943 MaxLineInfoNum=this->MaxLineInfoNum;
944 pLineInfo=this->pLineInfo;
945
946 // クラス情報
947 extern CDBClass *pobj_DBClass;
948 pobj_DBClass=this->pobj_DBClass;
949
950 // TypeDef情報
951 extern CDBTypeDef *pobj_DBTypeDef;
952 pobj_DBTypeDef=this->pobj_DBTypeDef;
953
954 //定数を取得
955 extern CONSTINFO **ppConstHash;
956 ppConstHash=this->ppConstHash;
957
958 //グローバル変数に関する情報
959 extern VARIABLE *GlobalVar;
960 extern int MaxGlobalVarNum;
961 GlobalVar=this->GlobalVar;
962 MaxGlobalVarNum=this->MaxGlobalVarNum;
963
964 //グローバル実行領域のサイズ
965 extern int GlobalOpBufferSize;
966 GlobalOpBufferSize=this->GlobalOpBufferSize;
967
968 //プロシージャ
969 extern char **ppMacroNames;
970 ppMacroNames=0;
971 extern SubInfo **ppSubHash;
972 extern int SubNum;
973 ppSubHash=this->ppSubHash;
974 SubNum=this->SubNum;
975
976 extern SubInfo *pSub_DebugSys_EndProc;
977 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
978
979 //ネイティブコードバッファ
980 extern char *OpBuffer;
981 OpBuffer=this->OpBuffer;
982}
983
984void CDebugSection::DeleteDebugInfo(void){
985 int i2;
986
987 //インクルード情報を解放
988 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
989 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
990 HeapDefaultFree(IncludeFileInfo.ppFileNames);
991
992 //グローバル変数に関する情報を解放
993 HeapDefaultFree(GlobalVar);
994
995 //ローカル変数に関する情報を解放
996 SubInfo *psi;
997 for(i2=0;i2<MAX_HASH;i2++){
998 psi=ppSubHash[i2];
999 while(psi){
1000 if(psi->bCompile)
1001 HeapDefaultFree(psi->pVar);
1002
1003 psi=psi->pNextData;
1004 }
1005 }
1006
1007 //クラスに関するメモリを解放
1008 delete pobj_DBClass;
1009 pobj_DBClass=0;
1010
1011 //サブルーチン情報のメモリ解放
1012 DeleteSubInfo(ppSubHash,0,0);
1013
1014 //定数に関する情報を解放
1015 DeleteConstInfo(ppConstHash);
1016
1017 //ソースコードを解放
1018 HeapDefaultFree(pBaseBuffer);
1019
1020 //コードと行番号の関係を解放
1021 HeapDefaultFree(pLineInfo);
1022
1023 //コードバッファを解放
1024 HeapDefaultFree(OpBuffer);
1025 OpBuffer=0;
1026
1027 HeapDefaultFree(SingleStepCodeBuffer);
1028 SingleStepCodeBuffer=0;
1029
1030 HeapDefaultFree(BreakStepCodeBuffer);
1031 BreakStepCodeBuffer=0;
1032}
1033
1034
1035
1036CDBDebugSection::CDBDebugSection(){
1037 ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
1038 num=0;
1039}
1040CDBDebugSection::~CDBDebugSection(){
1041 int i;
1042 for(i=0;i<num;i++){
1043 delete ppobj_ds[i];
1044 }
1045 HeapDefaultFree(ppobj_ds);
1046}
1047
1048BOOL CDBDebugSection::add(HMODULE hModule){
1049 CDebugSection *pobj_d;
1050 pobj_d=new CDebugSection();
1051 if(!pobj_d->load(hModule)){
1052 //デバッグ情報が存在しないとき
1053 delete pobj_d;
1054 return 0;
1055 }
1056
1057 ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
1058 ppobj_ds[num]=pobj_d;
1059 num++;
1060
1061 return 1;
1062}
1063
1064void CDBDebugSection::del(HMODULE hModule){
1065 int i;
1066 for(i=0;i<num;i++){
1067 if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
1068 delete ppobj_ds[i];
1069
1070 num--;
1071 for(;i<num;i++){
1072 ppobj_ds[i]=ppobj_ds[i+1];
1073 }
1074 break;
1075 }
1076 }
1077}
1078
1079void CDBDebugSection::choice(int index){
1080 pobj_now=ppobj_ds[index];
1081 pobj_now->choice();
1082}
1083
1084
1085
1086CDBDebugSection *pobj_DBDebugSection;
Note: See TracBrowser for help on using the repository browser.