source: dev/trunk/abdev/BasicCompiler_Common/DebugMiddleFile.cpp@ 150

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

CClass::vtblNumをリファクタリングした。
インターフェイスを継承したとき、Objectクラスがインターフェイスの後ろに配置されてしまうバグを修正(どんなときも、Objectクラスが一番最初に継承されるべき)

File size: 25.1 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().GetName().c_str());
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->Find(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,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->GetName().c_str());
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].GetName().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 GlobalProc **ppSubHash;
208 extern int SubNum;
209 GlobalProc *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()->GetName().c_str());
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->GetName().c_str());
315 i2+=lstrlen(buffer+i2)+1;
316
317 //仮想関数の数
318 *(long *)(buffer+i2)=pobj_c->GetVtblNum();
319 i2+=sizeof(long);
320
321 //アラインメント
322 *(long *)(buffer+i2)=pobj_c->iAlign;
323 i2+=sizeof(long);
324
325 //メンバ
326 *(long *)(buffer+i2)=(int)pobj_c->dynamicMembers.size();
327 i2+=sizeof(long);
328 foreach( CMember *member, pobj_c->dynamicMembers ){
329 // 名前
330 lstrcpy(buffer+i2,member->GetName().c_str());
331 i2+=lstrlen(buffer+i2)+1;
332
333 // 型
334 *(long *)(buffer+i2)=member->GetType().GetBasicType();
335 i2+=sizeof(long);
336
337 // 型の拡張情報
338 SetLpIndex_DebugFile(buffer,&i2,member->GetType());
339
340 // アクセシビリティ
341 *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
342 i2+=sizeof(Prototype::Accessibility);
343
344 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
345 i2+=sizeof(int)*MAX_ARRAYDIM;
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( const CMethod *pMethod, pobj_c->methods ){
358 *(Prototype::Accessibility *)(buffer+i2)=pMethod->GetAccessibility();
359 i2+=sizeof(Prototype::Accessibility);
360 if( pMethod->GetInheritsClassPtr() ){
361 lstrcpy(buffer+i2,pMethod->GetInheritsClassPtr()->GetName().c_str());
362 i2+=lstrlen(buffer+i2)+1;
363 }
364 else{
365 lstrcpy(buffer+i2,"");
366 i2+=lstrlen(buffer+i2)+1;
367 }
368 lstrcpy(buffer+i2,pMethod->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 // 名前
377 lstrcpy(buffer+i2,member->GetName().c_str());
378 i2+=lstrlen(buffer+i2)+1;
379
380 // 型
381 *(long *)(buffer+i2)=member->GetType().GetBasicType();
382 i2+=sizeof(long);
383
384 // 型の拡張情報
385 SetLpIndex_DebugFile(buffer,&i2,member->GetType());
386
387 // アクセシビリティ
388 *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
389 i2+=sizeof(Prototype::Accessibility);
390
391 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
392 i2+=sizeof(int)*MAX_ARRAYDIM;
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 pobj_CompilingClass = NULL;
435
436 i2=0;
437
438 //デバッグ用ファイルのバージョンをチェック
439 if(*(long *)(buffer+i2)<MDLFILE_VER){
440 HeapDefaultFree(buffer);
441 return 0;
442 }
443 i2+=sizeof(long);
444
445 //プラットフォームのビット数をチェック
446 if(*(long *)(buffer+i2)!=PLATFORM){
447 HeapDefaultFree(buffer);
448 return 0;
449 }
450 i2+=sizeof(long);
451
452 //インクルード情報
453 IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
454 i2+=sizeof(long);
455 IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *));
456 for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
457 if(buffer[i2]=='\0') break;
458 IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
459 lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2);
460 i2+=lstrlen(buffer+i2)+1;
461 }
462 for(i2++,i3=0;;i2++,i3++){
463 IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2];
464 if(IncludeFileInfo.LineOfFile[i3]==-1) break;
465 }
466
467 //ソースコード
468 i2++;
469 source.SetBuffer( buffer + i2 );
470 i2+=lstrlen(buffer+i2)+1;
471
472 //コードと行番号の関係
473 MaxLineInfoNum=*(long *)(buffer+i2);
474 i2+=sizeof(long);
475 pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1);
476 memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO));
477 i2+=MaxLineInfoNum*sizeof(LINEINFO);
478
479
480 ///////////////////////////////////////////
481 // クラス情報(名前のみ。詳細は後で取得)
482 ///////////////////////////////////////////
483
484 this->pobj_DBClass=new CDBClass();
485
486 int iMaxClassCount;
487 iMaxClassCount=*(long *)(buffer+i2);
488 i2+=sizeof(long);
489 for(i3=0;i3<iMaxClassCount;i3++){
490 //クラス名
491 // TODO: 名前空間が未完成
492 pobj_DBClass->AddClass(NamespaceScopes(),NamespaceScopesCollection(),buffer+i2,0);
493 i2+=lstrlen(buffer+i2)+1;
494 }
495
496 extern CDBClass *pobj_DBClass;
497 pobj_DBClass=this->pobj_DBClass;
498
499
500 //////////////////
501 // TypeDef情報
502 //////////////////
503
504 //初期化
505 Smoothie::Meta::typeDefs.clear();
506
507 //個数を取得
508 num=*(long *)(buffer+i2);
509 i2+=sizeof(long);
510 for(i3=0;i3<num;i3++){
511 temp5=buffer+i2;
512 i2+=lstrlen(buffer+i2)+1;
513
514 // 名前空間に未対応
515 Smoothie::Meta::typeDefs.push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2 ) );
516
517 i2+=lstrlen(buffer+i2)+1;
518 }
519
520 //定数を取得
521 GetConstInfo();
522 extern CONSTINFO **ppConstHash;
523 this->ppConstHash=ppConstHash;
524
525
526 //グローバル変数情報
527 globalVars.clear();
528 int maxGlobalVars=*(long *)(buffer+i2);
529 i2+=sizeof(long);
530 for(i3=0;i3<maxGlobalVars;i3++){
531
532 //変数名
533 char *name = buffer+i2;
534 i2+=lstrlen(buffer+i2)+1;
535
536 int basicType = *(long *)(buffer+i2);
537 i2+=sizeof(long);
538
539 Type type( basicType );
540 GetLpIndex_DebugFile(buffer,&i2,type);
541
542 bool isRef = (buffer[i2++]) ? true:false;
543
544 bool isArray = (buffer[i2++]) ? true:false;
545
546 Variable *pVar = new Variable( name, type, false, isRef );
547
548 if(isArray){
549 int SubScripts[MAX_ARRAYDIM];
550 for(i4=0;;i4++){
551 SubScripts[i4]=*(long *)(buffer+i2);
552 i2+=sizeof(long);
553
554 if(SubScripts[i4]==-1) break;
555 }
556
557 pVar->SetArray( SubScripts );
558 }
559
560 //レキシカルスコープ情報
561 pVar->ScopeStartAddress=*(long *)(buffer+i2);
562 i2+=sizeof(long);
563 pVar->ScopeEndAddress=*(long *)(buffer+i2);
564 i2+=sizeof(long);
565 pVar->ScopeLevel=*(long *)(buffer+i2);
566 i2+=sizeof(long);
567
568 //メモリ位置
569 pVar->offset=*(long *)(buffer+i2);
570 i2+=sizeof(long);
571
572 //変数を追加
573 globalVars.push_back( pVar );
574 }
575
576 //グローバル実行領域のサイズ
577 GlobalOpBufferSize=*(long *)(buffer+i2);
578 i2+=sizeof(long);
579
580 //プロシージャ情報
581 GlobalProc *pUserProc;
582 SubNum=*(long *)(buffer+i2);
583 i2+=sizeof(long);
584 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
585 for(int i6=0;i6<SubNum;i6++){
586 char szParentClassName[VN_SIZE];
587 lstrcpy(szParentClassName,buffer+i2);
588 i2+=lstrlen(buffer+i2)+1;
589
590 const CClass *pClass = NULL;
591 if(szParentClassName[0]){
592 pClass=pobj_DBClass->Find(szParentClassName);
593 }
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 // TODO: 名前空間が未完成
605 pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false );
606 pUserProc->pNextData=0;
607 pUserProc->id=id;
608 pUserProc->SetParentClass( pClass );
609
610 pUserProc->beginOpAddress=*(long *)(buffer+i2);
611 i2+=sizeof(long);
612 pUserProc->endOpAddress=*(long *)(buffer+i2);
613 i2+=sizeof(long);
614
615 pUserProc->CompleteCompile();
616
617 //ローカル変数情報
618 pUserProc->localVars.clear();
619 int maxLocalVar=*(long *)(buffer+i2);
620 i2+=sizeof(long);
621 for(i3=0;i3<maxLocalVar;i3++){
622 //変数名
623 char *name = buffer+i2;
624 i2+=lstrlen(buffer+i2)+1;
625
626 int basicType = *(long *)(buffer+i2);
627 i2+=sizeof(long);
628
629 Type type( basicType );
630 GetLpIndex_DebugFile(buffer,&i2,type);
631
632 bool isRef = (buffer[i2++]) ? true:false;
633
634 bool isArray = (buffer[i2++]) ? true:false;
635
636 Variable *pVar = new Variable( name, type, false, isRef );
637
638 if(isArray){
639 int SubScripts[MAX_ARRAYDIM];
640 for(i4=0;;i4++){
641 SubScripts[i4]=*(long *)(buffer+i2);
642 i2+=sizeof(long);
643
644 if(SubScripts[i4]==-1) break;
645 }
646
647 pVar->SetArray( SubScripts );
648 }
649
650 //レキシカルスコープ情報
651 pVar->ScopeStartAddress=*(long *)(buffer+i2);
652 i2+=sizeof(long);
653 pVar->ScopeEndAddress=*(long *)(buffer+i2);
654 i2+=sizeof(long);
655 pVar->ScopeLevel=*(long *)(buffer+i2);
656 i2+=sizeof(long);
657
658 //メモリ位置
659 pVar->offset=*(long *)(buffer+i2);
660 i2+=sizeof(long);
661
662 //変数を追加
663 pUserProc->localVars.push_back( pVar );
664 }
665
666
667 /////////////////////////////////
668 // 格納位置を計算してpUserProcをセット
669 /////////////////////////////////
670
671 i4=hash_default(pUserProc->GetName().c_str());
672
673 GlobalProc *psi2;
674 if(ppSubHash[i4]){
675 psi2=ppSubHash[i4];
676 while(1){
677 if(psi2->pNextData==0){
678 psi2->pNextData=pUserProc;
679 break;
680 }
681 psi2=psi2->pNextData;
682 }
683 }
684 else{
685 ppSubHash[i4]=pUserProc;
686 }
687 }
688
689 //クラス情報
690 CClass *pobj_c;
691 for(i3=0;i3<iMaxClassCount;i3++){
692 //クラス名
693 char szClassName[VN_SIZE];
694 lstrcpy(szClassName,buffer+i2);
695 i2+=lstrlen(buffer+i2)+1;
696
697 pobj_c = const_cast<CClass *>( pobj_DBClass->Find(szClassName) );
698
699 //仮想関数の数
700 pobj_c->SetVtblNum( *(long *)(buffer+i2) );
701 i2+=sizeof(long);
702
703 //アラインメント
704 pobj_c->iAlign=*(long *)(buffer+i2);
705 i2+=sizeof(long);
706
707 //静的メンバ
708 int nDynamicMember = *(long *)(buffer+i2);
709 i2+=sizeof(long);
710 for( i4=0; i4<nDynamicMember; i4++ ){
711 // 名前
712 string name = (char *)(buffer+i2);
713 i2+=lstrlen(buffer+i2)+1;
714
715 // 型
716 Type type( *(long *)(buffer+i2) );
717 i2+=sizeof(long);
718
719 // 型の拡張情報
720 GetLpIndex_DebugFile(buffer,&i2,type);
721
722 // アクセシビリティ
723 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
724 i2+=sizeof(Prototype::Accessibility);
725
726 CMember *member=new CMember( accessibility, name, type, false );
727
728 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
729 i2+=sizeof(int)*MAX_ARRAYDIM;
730
731 pobj_c->dynamicMembers.push_back( member );
732 }
733
734 //メソッド
735 int nMethod = *(long *)(buffer+i2);
736 i2+=sizeof(long);
737 for( i4=0; i4<nMethod; i4++ ){
738
739 Prototype::Accessibility accessibility=*(Prototype::Accessibility *)(buffer+i2);
740 i2+=sizeof(Prototype::Accessibility);
741
742 char szInherits[VN_SIZE];
743 lstrcpy(szInherits,buffer+i2);
744 i2+=lstrlen(buffer+i2)+1;
745
746 const CClass *pobj_InheritsClass = NULL;
747 if(szInherits[0]){
748 pobj_InheritsClass=pobj_DBClass->Find(szInherits);
749 }
750
751 lstrcpy(temp2,buffer+i2);
752 i2+=lstrlen(buffer+i2)+1;
753
754 const CClass *pobj_temp_c;
755 pobj_temp_c=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
764 CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, 0,0,false, pobj_InheritsClass);
765
766 pobj_c->methods.push_back( pMethod );
767 }
768
769 //静的メンバ
770 int nStaticMember = *(long *)(buffer+i2);
771 i2+=sizeof(long);
772 for( i4=0; i4<nStaticMember; i4++ ){
773 // 名前
774 string name = (char *)(buffer+i2);
775 i2+=lstrlen(buffer+i2)+1;
776
777 // 型
778 Type type( *(long *)(buffer+i2) );
779 i2+=sizeof(long);
780
781 // 型の拡張情報
782 GetLpIndex_DebugFile(buffer,&i2,type);
783
784 // アクセシビリティ
785 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
786 i2+=sizeof(Prototype::Accessibility);
787
788 CMember *member=new CMember( accessibility, name, type, false );
789
790 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
791 i2+=sizeof(int)*MAX_ARRAYDIM;
792
793 pobj_c->staticMembers.push_back( member );
794 }
795 }
796
797 HeapDefaultFree(buffer);
798 buffer=0;
799
800
801
802
803 extern GlobalProc **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 Smoothie::Lexical::source = source;
937
938 //コードと行番号の関係
939 extern int MaxLineInfoNum;
940 extern LINEINFO *pLineInfo;
941 MaxLineInfoNum=this->MaxLineInfoNum;
942 pLineInfo=this->pLineInfo;
943
944 // クラス情報
945 extern CDBClass *pobj_DBClass;
946 pobj_DBClass=this->pobj_DBClass;
947
948 //定数を取得
949 extern CONSTINFO **ppConstHash;
950 ppConstHash=this->ppConstHash;
951
952 //グローバル実行領域のサイズ
953 extern int GlobalOpBufferSize;
954 GlobalOpBufferSize=this->GlobalOpBufferSize;
955
956 //プロシージャ
957 extern char **ppMacroNames;
958 ppMacroNames=0;
959 extern GlobalProc **ppSubHash;
960 extern int SubNum;
961 ppSubHash=this->ppSubHash;
962 SubNum=this->SubNum;
963
964 extern UserProc *pSub_DebugSys_EndProc;
965 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
966
967 //ネイティブコードバッファ
968 extern char *OpBuffer;
969 OpBuffer=this->OpBuffer;
970}
971
972void CDebugSection::DeleteDebugInfo(void){
973 int i2;
974
975 //インクルード情報を解放
976 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
977 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
978 HeapDefaultFree(IncludeFileInfo.ppFileNames);
979
980 //クラスに関するメモリを解放
981 delete pobj_DBClass;
982 pobj_DBClass=0;
983
984 //サブルーチン情報のメモリ解放
985 DeleteSubInfo(ppSubHash,0,0);
986
987 //定数に関する情報を解放
988 DeleteConstInfo(ppConstHash);
989
990 //コードと行番号の関係を解放
991 HeapDefaultFree(pLineInfo);
992
993 //コードバッファを解放
994 HeapDefaultFree(OpBuffer);
995 OpBuffer=0;
996
997 HeapDefaultFree(SingleStepCodeBuffer);
998 SingleStepCodeBuffer=0;
999
1000 HeapDefaultFree(BreakStepCodeBuffer);
1001 BreakStepCodeBuffer=0;
1002}
1003
1004
1005
1006CDBDebugSection::CDBDebugSection(){
1007 ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
1008 num=0;
1009}
1010CDBDebugSection::~CDBDebugSection(){
1011 int i;
1012 for(i=0;i<num;i++){
1013 delete ppobj_ds[i];
1014 }
1015 HeapDefaultFree(ppobj_ds);
1016}
1017
1018BOOL CDBDebugSection::add(HMODULE hModule){
1019 CDebugSection *pobj_d;
1020 pobj_d=new CDebugSection();
1021 if(!pobj_d->load(hModule)){
1022 //デバッグ情報が存在しないとき
1023 delete pobj_d;
1024 return 0;
1025 }
1026
1027 ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
1028 ppobj_ds[num]=pobj_d;
1029 num++;
1030
1031 return 1;
1032}
1033
1034void CDBDebugSection::del(HMODULE hModule){
1035 int i;
1036 for(i=0;i<num;i++){
1037 if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
1038 delete ppobj_ds[i];
1039
1040 num--;
1041 for(;i<num;i++){
1042 ppobj_ds[i]=ppobj_ds[i+1];
1043 }
1044 break;
1045 }
1046 }
1047}
1048
1049void CDBDebugSection::choice(int index){
1050 pobj_now=ppobj_ds[index];
1051 pobj_now->choice();
1052}
1053
1054
1055
1056CDBDebugSection *pobj_DBDebugSection;
Note: See TracBrowser for help on using the repository browser.