source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 137

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

アクセシビリティ周りをリファクタリングした。

File size: 25.2 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,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->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->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 // 名前
330 lstrcpy(buffer+i2,pobj_c->ppobj_Member[i4]->GetName().c_str());
331 i2+=lstrlen(buffer+i2)+1;
332
333 // 型
334 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetType().GetBasicType();
335 i2+=sizeof(long);
336
337 // 型の拡張情報
338 SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->GetType());
339
340 // アクセシビリティ
341 *(Prototype::Accessibility *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetAccessibility();
342 i2+=sizeof(Prototype::Accessibility);
343
344 memcpy(buffer+i2,pobj_c->ppobj_Member[i4]->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->vtbl_num=*(long *)(buffer+i2);
701 i2+=sizeof(long);
702
703 //アラインメント
704 pobj_c->iAlign=*(long *)(buffer+i2);
705 i2+=sizeof(long);
706
707 //メンバ
708 pobj_c->iMemberNum=*(long *)(buffer+i2);
709 i2+=sizeof(long);
710 pobj_c->ppobj_Member=
711 (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *));
712 for(i4=0;i4<pobj_c->iMemberNum;i4++){
713
714 // 名前
715 string name = (char *)(buffer+i2);
716 i2+=lstrlen(buffer+i2)+1;
717
718 // 型
719 Type type( *(long *)(buffer+i2) );
720 i2+=sizeof(long);
721
722 // 型の拡張情報
723 GetLpIndex_DebugFile(buffer,&i2,type);
724
725 // アクセシビリティ
726 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
727 i2+=sizeof(Prototype::Accessibility);
728
729 pobj_c->ppobj_Member[i4]=new CMember( accessibility, name, type, false );
730
731 memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
732 i2+=sizeof(int)*MAX_ARRAYDIM;
733 }
734
735 //メソッド
736 int nMethod = *(long *)(buffer+i2);
737 i2+=sizeof(long);
738 for( i4=0; i4<nMethod; i4++ ){
739
740 Prototype::Accessibility accessibility=*(Prototype::Accessibility *)(buffer+i2);
741 i2+=sizeof(Prototype::Accessibility);
742
743 char szInherits[VN_SIZE];
744 lstrcpy(szInherits,buffer+i2);
745 i2+=lstrlen(buffer+i2)+1;
746
747 const CClass *pobj_InheritsClass = NULL;
748 if(szInherits[0]){
749 pobj_InheritsClass=pobj_DBClass->Find(szInherits);
750 }
751
752 lstrcpy(temp2,buffer+i2);
753 i2+=lstrlen(buffer+i2)+1;
754
755 const CClass *pobj_temp_c;
756 pobj_temp_c=pobj_InheritsClass;
757 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
758 i5=hash_default(temp2);
759 pUserProc=ppSubHash[i5];
760 while(1){
761 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
762 pUserProc=pUserProc->pNextData;
763 }
764
765 CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, 0,0,false, pobj_InheritsClass);
766
767 pobj_c->methods.push_back( pMethod );
768 }
769
770 //静的メンバ
771 int nStaticMember = *(long *)(buffer+i2);
772 i2+=sizeof(long);
773 for( i4=0; i4<nStaticMember; i4++ ){
774 // 名前
775 string name = (char *)(buffer+i2);
776 i2+=lstrlen(buffer+i2)+1;
777
778 // 型
779 Type type( *(long *)(buffer+i2) );
780 i2+=sizeof(long);
781
782 // 型の拡張情報
783 GetLpIndex_DebugFile(buffer,&i2,type);
784
785 // アクセシビリティ
786 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
787 i2+=sizeof(Prototype::Accessibility);
788
789 CMember *member=new CMember( accessibility, name, type, false );
790
791 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
792 i2+=sizeof(int)*MAX_ARRAYDIM;
793
794 pobj_c->staticMembers.push_back( member );
795 }
796 }
797
798 HeapDefaultFree(buffer);
799 buffer=0;
800
801
802
803
804 extern GlobalProc **ppSubHash;
805 ppSubHash=this->ppSubHash;
806 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
807
808
809 SingleStepCodeBuffer=MakeSingleStepCode();
810
811
812 /////////////////////////////
813 // ブレークポイントを適用
814 /////////////////////////////
815
816 //インクルード情報
817 extern INCLUDEFILEINFO IncludeFileInfo;
818 IncludeFileInfo=this->IncludeFileInfo;
819
820 //コードと行番号の関係
821 extern int MaxLineInfoNum;
822 extern LINEINFO *pLineInfo;
823 MaxLineInfoNum=this->MaxLineInfoNum;
824 pLineInfo=this->pLineInfo;
825
826 BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
827
828 //プロセスメモリにコピー
829 extern HANDLE hDebugProcess;
830 SIZE_T accessBytes;
831 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
832 BreakStepCodeBuffer,
833 SizeOf_CodeSection,&accessBytes);
834
835
836 return 1;
837}
838
839BOOL CDebugSection::load(HMODULE hModule){
840 if(buffer){
841 HeapDefaultFree(buffer);
842 buffer=0;
843 }
844
845
846 extern HANDLE hDebugProcess;
847 SIZE_T accessBytes;
848 IMAGE_DOS_HEADER ImageDosHeader;
849 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes);
850
851 int pe_size;
852#ifdef _AMD64_
853 IMAGE_NT_HEADERS64 pe_hdr;
854 pe_size=sizeof(IMAGE_NT_HEADERS64);
855#else
856 IMAGE_NT_HEADERS pe_hdr;
857 pe_size=sizeof(IMAGE_NT_HEADERS);
858#endif
859 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes);
860
861 IMAGE_SECTION_HEADER *pSectionHdr;
862 pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
863 ReadProcessMemory(hDebugProcess,
864 (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
865 pSectionHdr,
866 pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
867 &accessBytes);
868
869 int i;
870 for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
871
872 //リライタブルセクション内の情報
873 if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
874 dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
875 }
876
877 //コードセクション内の情報
878 if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
879 dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
880 SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
881 }
882
883 //デバッグセクション内の情報
884 if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
885 length=pSectionHdr[i].Misc.VirtualSize;
886 buffer=(char *)HeapAlloc(hHeap,0,length+1);
887
888 ReadProcessMemory(hDebugProcess,
889 (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
890 buffer,
891 length,
892 &accessBytes);
893 buffer[length]=0;
894 }
895
896 }
897 HeapDefaultFree(pSectionHdr);
898
899 if(!buffer) return 0;
900
901
902 dwImageBase=(DWORD)(ULONG_PTR)hModule;
903
904
905
906 if(OpBuffer) HeapDefaultFree(OpBuffer);
907 OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
908
909 ReadProcessMemory(hDebugProcess,
910 (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
911 SizeOf_CodeSection,&accessBytes);
912
913
914 return __load();
915}
916
917void CDebugSection::choice(void){
918 //イメージベース
919 extern DWORD ImageBase;
920 ImageBase=this->dwImageBase;
921
922 //リライタブルセクションのRVA
923 extern int MemPos_RWSection;
924 MemPos_RWSection=this->dwRVA_RWSection;
925
926 //コードセクションのRVAとサイズ
927 extern int MemPos_CodeSection;
928 extern int FileSize_CodeSection;
929 MemPos_CodeSection=this->dwRVA_CodeSection;
930 FileSize_CodeSection=this->SizeOf_CodeSection;
931
932 //インクルード情報
933 extern INCLUDEFILEINFO IncludeFileInfo;
934 IncludeFileInfo=this->IncludeFileInfo;
935
936 //ソースコード
937 Smoothie::Lexical::source = source;
938
939 //コードと行番号の関係
940 extern int MaxLineInfoNum;
941 extern LINEINFO *pLineInfo;
942 MaxLineInfoNum=this->MaxLineInfoNum;
943 pLineInfo=this->pLineInfo;
944
945 // クラス情報
946 extern CDBClass *pobj_DBClass;
947 pobj_DBClass=this->pobj_DBClass;
948
949 //定数を取得
950 extern CONSTINFO **ppConstHash;
951 ppConstHash=this->ppConstHash;
952
953 //グローバル実行領域のサイズ
954 extern int GlobalOpBufferSize;
955 GlobalOpBufferSize=this->GlobalOpBufferSize;
956
957 //プロシージャ
958 extern char **ppMacroNames;
959 ppMacroNames=0;
960 extern GlobalProc **ppSubHash;
961 extern int SubNum;
962 ppSubHash=this->ppSubHash;
963 SubNum=this->SubNum;
964
965 extern UserProc *pSub_DebugSys_EndProc;
966 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
967
968 //ネイティブコードバッファ
969 extern char *OpBuffer;
970 OpBuffer=this->OpBuffer;
971}
972
973void CDebugSection::DeleteDebugInfo(void){
974 int i2;
975
976 //インクルード情報を解放
977 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
978 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
979 HeapDefaultFree(IncludeFileInfo.ppFileNames);
980
981 //クラスに関するメモリを解放
982 delete pobj_DBClass;
983 pobj_DBClass=0;
984
985 //サブルーチン情報のメモリ解放
986 DeleteSubInfo(ppSubHash,0,0);
987
988 //定数に関する情報を解放
989 DeleteConstInfo(ppConstHash);
990
991 //コードと行番号の関係を解放
992 HeapDefaultFree(pLineInfo);
993
994 //コードバッファを解放
995 HeapDefaultFree(OpBuffer);
996 OpBuffer=0;
997
998 HeapDefaultFree(SingleStepCodeBuffer);
999 SingleStepCodeBuffer=0;
1000
1001 HeapDefaultFree(BreakStepCodeBuffer);
1002 BreakStepCodeBuffer=0;
1003}
1004
1005
1006
1007CDBDebugSection::CDBDebugSection(){
1008 ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
1009 num=0;
1010}
1011CDBDebugSection::~CDBDebugSection(){
1012 int i;
1013 for(i=0;i<num;i++){
1014 delete ppobj_ds[i];
1015 }
1016 HeapDefaultFree(ppobj_ds);
1017}
1018
1019BOOL CDBDebugSection::add(HMODULE hModule){
1020 CDebugSection *pobj_d;
1021 pobj_d=new CDebugSection();
1022 if(!pobj_d->load(hModule)){
1023 //デバッグ情報が存在しないとき
1024 delete pobj_d;
1025 return 0;
1026 }
1027
1028 ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
1029 ppobj_ds[num]=pobj_d;
1030 num++;
1031
1032 return 1;
1033}
1034
1035void CDBDebugSection::del(HMODULE hModule){
1036 int i;
1037 for(i=0;i<num;i++){
1038 if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
1039 delete ppobj_ds[i];
1040
1041 num--;
1042 for(;i<num;i++){
1043 ppobj_ds[i]=ppobj_ds[i+1];
1044 }
1045 break;
1046 }
1047 }
1048}
1049
1050void CDBDebugSection::choice(int index){
1051 pobj_now=ppobj_ds[index];
1052 pobj_now->choice();
1053}
1054
1055
1056
1057CDBDebugSection *pobj_DBDebugSection;
Note: See TracBrowser for help on using the repository browser.