source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 44

Last change on this file since 44 was 16, checked in by dai_9181, 18 years ago

グローバル領域外のConst定義を初期段階で収集しないようにしました。

File size: 25.9 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){
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){
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)=pobj_c->iMethodNum;
367 i2+=sizeof(long);
368 for(i4=0;i4<pobj_c->iMethodNum;i4++){
369 *(long *)(buffer+i2)=pobj_c->ppobj_Method[i4]->dwAccess;
370 i2+=sizeof(long);
371 if(pobj_c->ppobj_Method[i4]->pobj_InheritsClass){
372 lstrcpy(buffer+i2,pobj_c->ppobj_Method[i4]->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,pobj_c->ppobj_Method[i4]->psi->name);
380 i2+=lstrlen(buffer+i2)+1;
381 }
382
383 //静的メンバ
384 *(long *)(buffer+i2)=pobj_c->iStaticMemberNum;
385 i2+=sizeof(long);
386 for(i4=0;i4<pobj_c->iStaticMemberNum;i4++){
387 lstrcpy(buffer+i2,pobj_c->ppobj_StaticMember[i4]->name);
388 i2+=lstrlen(buffer+i2)+1;
389
390 memcpy(buffer+i2,pobj_c->ppobj_StaticMember[i4]->SubScripts,sizeof(int)*MAX_ARRAYDIM);
391 i2+=sizeof(int)*MAX_ARRAYDIM;
392
393 //型
394 *(long *)(buffer+i2)=pobj_c->ppobj_StaticMember[i4]->TypeInfo.type;
395 i2+=sizeof(long);
396
397 //型の拡張情報
398 SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_StaticMember[i4]->TypeInfo.type,pobj_c->ppobj_StaticMember[i4]->TypeInfo.u.lpIndex);
399
400 *(long *)(buffer+i2)=pobj_c->ppobj_StaticMember[i4]->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=(SUBINFO *)HeapAlloc(hHeap,0,sizeof(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->ParmNum=0;
621 psi->pParmInfo=0;
622 psi->RealParmNum=0;
623 psi->pRealParmInfo=0;
624 psi->bCompile=1;
625
626 //ローカル変数情報
627 psi->VarNum=*(long *)(buffer+i2);
628 i2+=sizeof(long);
629 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,psi->VarNum*sizeof(VARIABLE)+1);
630 for(i4=0;i4<psi->VarNum;i4++){
631 VARIABLE *pVar=&psi->pVar[i4];
632
633 //ローカル変数名
634 lstrcpy(pVar->name,buffer+i2);
635 i2+=lstrlen(buffer+i2)+1;
636
637 //型
638 pVar->type=*(long *)(buffer+i2);
639 i2+=sizeof(long);
640
641 //型の拡張情報
642 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
643
644 //参照型パラメータかどうか
645 pVar->fRef=(long)buffer[i2++];
646
647 //配列かどうか
648 pVar->bArray=(long)buffer[i2++];
649 if(pVar->bArray){
650 for(i5=0;;i5++){
651 //配列要素
652 pVar->SubScripts[i5]=*(long *)(buffer+i2);
653 i2+=sizeof(long);
654
655 if(pVar->SubScripts[i5]==-1) break;
656 }
657 }
658
659 //レキシカルスコープ情報
660 pVar->ScopeStartAddress=*(long *)(buffer+i2);
661 i2+=sizeof(long);
662 pVar->ScopeEndAddress=*(long *)(buffer+i2);
663 i2+=sizeof(long);
664 pVar->ScopeLevel=*(long *)(buffer+i2);
665 i2+=sizeof(long);
666
667 //メモリ上の位置
668 pVar->offset=*(long *)(buffer+i2);
669 i2+=sizeof(long);
670 }
671
672
673 /////////////////////////////////
674 // 格納位置を計算してpsiをセット
675 /////////////////////////////////
676
677 i4=hash_default(psi->name);
678
679 SUBINFO *psi2;
680 if(ppSubHash[i4]){
681 psi2=ppSubHash[i4];
682 while(1){
683 if(psi2->pNextData==0){
684 psi2->pNextData=psi;
685 break;
686 }
687 psi2=psi2->pNextData;
688 }
689 }
690 else{
691 ppSubHash[i4]=psi;
692 }
693 }
694
695 //クラス情報
696 CClass *pobj_c;
697 for(i3=0;i3<iMaxClassCount;i3++){
698 //クラス名
699 char szClassName[VN_SIZE];
700 lstrcpy(szClassName,buffer+i2);
701 i2+=lstrlen(buffer+i2)+1;
702
703 pobj_c=pobj_DBClass->check(szClassName);
704
705 //仮想関数の数
706 pobj_c->vtbl_num=*(long *)(buffer+i2);
707 i2+=sizeof(long);
708
709 //アラインメント
710 pobj_c->iAlign=*(long *)(buffer+i2);
711 i2+=sizeof(long);
712
713 //メンバ
714 pobj_c->iMemberNum=*(long *)(buffer+i2);
715 i2+=sizeof(long);
716 pobj_c->ppobj_Member=
717 (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *));
718 for(i4=0;i4<pobj_c->iMemberNum;i4++){
719 pobj_c->ppobj_Member[i4]=new CMember();
720
721 pobj_c->ppobj_Member[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
722 lstrcpy(pobj_c->ppobj_Member[i4]->name,buffer+i2);
723 i2+=lstrlen(buffer+i2)+1;
724
725 memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
726 i2+=sizeof(int)*MAX_ARRAYDIM;
727
728 //型
729 pobj_c->ppobj_Member[i4]->TypeInfo.type=*(long *)(buffer+i2);
730 i2+=sizeof(long);
731
732 //型の拡張情報
733 GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,&pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
734
735 pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2);
736 i2+=sizeof(long);
737 }
738
739 //メソッド
740 pobj_c->iMethodNum=*(long *)(buffer+i2);
741 i2+=sizeof(long);
742 pobj_c->ppobj_Method=
743 (CMethod **)HeapAlloc(hHeap,0,pobj_c->iMethodNum*sizeof(CMethod *));
744 for(i4=0;i4<pobj_c->iMethodNum;i4++){
745 pobj_c->ppobj_Method[i4]=new CMethod();
746
747 pobj_c->ppobj_Method[i4]->dwAccess=*(long *)(buffer+i2);
748 i2+=sizeof(long);
749
750 char szInherits[VN_SIZE];
751 lstrcpy(szInherits,buffer+i2);
752 i2+=lstrlen(buffer+i2)+1;
753
754 if(szInherits[0])
755 pobj_c->ppobj_Method[i4]->pobj_InheritsClass=pobj_DBClass->check(szInherits);
756 else pobj_c->ppobj_Method[i4]->pobj_InheritsClass=0;
757
758 lstrcpy(temp2,buffer+i2);
759 i2+=lstrlen(buffer+i2)+1;
760
761 CClass *pobj_temp_c;
762 pobj_temp_c=pobj_c->ppobj_Method[i4]->pobj_InheritsClass;
763 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
764 i5=hash_default(temp2);
765 psi=ppSubHash[i5];
766 while(1){
767 if(lstrcmp(psi->name,temp2)==0&&psi->pobj_ParentClass==pobj_temp_c) break;
768 psi=psi->pNextData;
769 }
770 pobj_c->ppobj_Method[i4]->psi=psi;
771 }
772
773 //静的メンバ
774 pobj_c->iStaticMemberNum=*(long *)(buffer+i2);
775 i2+=sizeof(long);
776 pobj_c->ppobj_StaticMember=
777 (CMember **)HeapAlloc(hHeap,0,pobj_c->iStaticMemberNum*sizeof(CMember *));
778 for(i4=0;i4<pobj_c->iStaticMemberNum;i4++){
779 pobj_c->ppobj_StaticMember[i4]=new CMember();
780
781 pobj_c->ppobj_StaticMember[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
782 lstrcpy(pobj_c->ppobj_StaticMember[i4]->name,buffer+i2);
783 i2+=lstrlen(buffer+i2)+1;
784
785 memcpy(pobj_c->ppobj_StaticMember[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
786 i2+=sizeof(int)*MAX_ARRAYDIM;
787
788 //型
789 pobj_c->ppobj_StaticMember[i4]->TypeInfo.type=*(long *)(buffer+i2);
790 i2+=sizeof(long);
791
792 //型の拡張情報
793 GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_StaticMember[i4]->TypeInfo.type,&pobj_c->ppobj_StaticMember[i4]->TypeInfo.u.lpIndex);
794
795 pobj_c->ppobj_StaticMember[i4]->dwAccess=*(long *)(buffer+i2);
796 i2+=sizeof(long);
797 }
798 }
799
800 HeapDefaultFree(buffer);
801 buffer=0;
802
803
804
805
806 extern SUBINFO **ppSubHash;
807 ppSubHash=this->ppSubHash;
808 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
809
810
811 SingleStepCodeBuffer=MakeSingleStepCode();
812
813
814 /////////////////////////////
815 // ブレークポイントを適用
816 /////////////////////////////
817
818 //インクルード情報
819 extern INCLUDEFILEINFO IncludeFileInfo;
820 IncludeFileInfo=this->IncludeFileInfo;
821
822 //コードと行番号の関係
823 extern int MaxLineInfoNum;
824 extern LINEINFO *pLineInfo;
825 MaxLineInfoNum=this->MaxLineInfoNum;
826 pLineInfo=this->pLineInfo;
827
828 BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
829
830 //プロセスメモリにコピー
831 extern HANDLE hDebugProcess;
832 SIZE_T stAccBytes;
833 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
834 BreakStepCodeBuffer,
835 SizeOf_CodeSection,&stAccBytes);
836
837
838 return 1;
839}
840
841BOOL CDebugSection::load(HMODULE hModule){
842 if(buffer){
843 HeapDefaultFree(buffer);
844 buffer=0;
845 }
846
847
848 extern HANDLE hDebugProcess;
849 SIZE_T stAccBytes;
850 IMAGE_DOS_HEADER ImageDosHeader;
851 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&stAccBytes);
852
853 int pe_size;
854#ifdef _AMD64_
855 IMAGE_NT_HEADERS64 pe_hdr;
856 pe_size=sizeof(IMAGE_NT_HEADERS64);
857#else
858 IMAGE_NT_HEADERS pe_hdr;
859 pe_size=sizeof(IMAGE_NT_HEADERS);
860#endif
861 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&stAccBytes);
862
863 IMAGE_SECTION_HEADER *pSectionHdr;
864 pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
865 ReadProcessMemory(hDebugProcess,
866 (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
867 pSectionHdr,
868 pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
869 &stAccBytes);
870
871 int i;
872 for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
873
874 //リライタブルセクション内の情報
875 if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
876 dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
877 }
878
879 //コードセクション内の情報
880 if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
881 dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
882 SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
883 }
884
885 //デバッグセクション内の情報
886 if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
887 length=pSectionHdr[i].Misc.VirtualSize;
888 buffer=(char *)HeapAlloc(hHeap,0,length+1);
889
890 ReadProcessMemory(hDebugProcess,
891 (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
892 buffer,
893 length,
894 &stAccBytes);
895 buffer[length]=0;
896 }
897
898 }
899 HeapDefaultFree(pSectionHdr);
900
901 if(!buffer) return 0;
902
903
904 dwImageBase=(DWORD)(ULONG_PTR)hModule;
905
906
907
908 if(OpBuffer) HeapDefaultFree(OpBuffer);
909 OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
910
911 ReadProcessMemory(hDebugProcess,
912 (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
913 SizeOf_CodeSection,&stAccBytes);
914
915
916 return __load();
917}
918
919void CDebugSection::choice(void){
920 //イメージベース
921 extern DWORD ImageBase;
922 ImageBase=this->dwImageBase;
923
924 //リライタブルセクションのRVA
925 extern int MemPos_RWSection;
926 MemPos_RWSection=this->dwRVA_RWSection;
927
928 //コードセクションのRVAとサイズ
929 extern int MemPos_CodeSection;
930 extern int FileSize_CodeSection;
931 MemPos_CodeSection=this->dwRVA_CodeSection;
932 FileSize_CodeSection=this->SizeOf_CodeSection;
933
934 //インクルード情報
935 extern INCLUDEFILEINFO IncludeFileInfo;
936 IncludeFileInfo=this->IncludeFileInfo;
937
938 //ソースコード
939 extern char *pBaseBuffer;
940 extern char *basbuf;
941 pBaseBuffer=this->pBaseBuffer;
942 basbuf=this->basbuf;
943
944 //コードと行番号の関係
945 extern int MaxLineInfoNum;
946 extern LINEINFO *pLineInfo;
947 MaxLineInfoNum=this->MaxLineInfoNum;
948 pLineInfo=this->pLineInfo;
949
950 // クラス情報
951 extern CDBClass *pobj_DBClass;
952 pobj_DBClass=this->pobj_DBClass;
953
954 // TypeDef情報
955 extern CDBTypeDef *pobj_DBTypeDef;
956 pobj_DBTypeDef=this->pobj_DBTypeDef;
957
958 //定数を取得
959 extern CONSTINFO **ppConstHash;
960 ppConstHash=this->ppConstHash;
961
962 //グローバル変数に関する情報
963 extern VARIABLE *GlobalVar;
964 extern int MaxGlobalVarNum;
965 GlobalVar=this->GlobalVar;
966 MaxGlobalVarNum=this->MaxGlobalVarNum;
967
968 //グローバル実行領域のサイズ
969 extern int GlobalOpBufferSize;
970 GlobalOpBufferSize=this->GlobalOpBufferSize;
971
972 //プロシージャ
973 extern char **ppMacroNames;
974 ppMacroNames=0;
975 extern SUBINFO **ppSubHash;
976 extern int SubNum;
977 ppSubHash=this->ppSubHash;
978 SubNum=this->SubNum;
979
980 extern SUBINFO *pSub_DebugSys_EndProc;
981 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
982
983 //ネイティブコードバッファ
984 extern char *OpBuffer;
985 OpBuffer=this->OpBuffer;
986}
987
988void CDebugSection::DeleteDebugInfo(void){
989 int i2;
990
991 //インクルード情報を解放
992 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
993 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
994 HeapDefaultFree(IncludeFileInfo.ppFileNames);
995
996 //グローバル変数に関する情報を解放
997 HeapDefaultFree(GlobalVar);
998
999 //ローカル変数に関する情報を解放
1000 SUBINFO *psi;
1001 for(i2=0;i2<MAX_HASH;i2++){
1002 psi=ppSubHash[i2];
1003 while(psi){
1004 if(psi->bCompile)
1005 HeapDefaultFree(psi->pVar);
1006
1007 psi=psi->pNextData;
1008 }
1009 }
1010
1011 //クラスに関するメモリを解放
1012 delete pobj_DBClass;
1013 pobj_DBClass=0;
1014
1015 //サブルーチン情報のメモリ解放
1016 DeleteSubInfo(ppSubHash,0,0);
1017
1018 //定数に関する情報を解放
1019 DeleteConstInfo(ppConstHash);
1020
1021 //ソースコードを解放
1022 HeapDefaultFree(pBaseBuffer);
1023
1024 //コードと行番号の関係を解放
1025 HeapDefaultFree(pLineInfo);
1026
1027 //コードバッファを解放
1028 HeapDefaultFree(OpBuffer);
1029 OpBuffer=0;
1030
1031 HeapDefaultFree(SingleStepCodeBuffer);
1032 SingleStepCodeBuffer=0;
1033
1034 HeapDefaultFree(BreakStepCodeBuffer);
1035 BreakStepCodeBuffer=0;
1036}
1037
1038
1039
1040CDBDebugSection::CDBDebugSection(){
1041 ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
1042 num=0;
1043}
1044CDBDebugSection::~CDBDebugSection(){
1045 int i;
1046 for(i=0;i<num;i++){
1047 delete ppobj_ds[i];
1048 }
1049 HeapDefaultFree(ppobj_ds);
1050}
1051
1052BOOL CDBDebugSection::add(HMODULE hModule){
1053 CDebugSection *pobj_d;
1054 pobj_d=new CDebugSection();
1055 if(!pobj_d->load(hModule)){
1056 //デバッグ情報が存在しないとき
1057 delete pobj_d;
1058 return 0;
1059 }
1060
1061 ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
1062 ppobj_ds[num]=pobj_d;
1063 num++;
1064
1065 return 1;
1066}
1067
1068void CDBDebugSection::del(HMODULE hModule){
1069 int i;
1070 for(i=0;i<num;i++){
1071 if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
1072 delete ppobj_ds[i];
1073
1074 num--;
1075 for(;i<num;i++){
1076 ppobj_ds[i]=ppobj_ds[i+1];
1077 }
1078 break;
1079 }
1080 }
1081}
1082
1083void CDBDebugSection::choice(int index){
1084 pobj_now=ppobj_ds[index];
1085 pobj_now->choice();
1086}
1087
1088
1089
1090CDBDebugSection *pobj_DBDebugSection;
Note: See TracBrowser for help on using the repository browser.