source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 75

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

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

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