source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 78

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

CTypeDef → TypeDef
Houseクラスを追加。
オーバーロードレベルの種類を追加(レベル1に挿入)

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