source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 99

Last change on this file since 99 was 88, checked in by dai_9181, 18 years ago

House→Smoothie
Sourceクラスを用意した。

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