source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 135

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

Method/Memberのリファクタリング

File size: 24.8 KB
RevLine 
[4]1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
[5]6#include "../BasicCompiler32/opcode.h"
[4]7#endif
8
9#define MDLFILE_VER 0x70000003
10
11
[75]12void SetLpIndex_DebugFile(char *buffer,int *p,const Type &type){
13 if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
[131]14 lstrcpy(buffer+(*p),type.GetClass().GetName().c_str());
[4]15 (*p)+=lstrlen(buffer+(*p))+1;
16 }
17 else{
[75]18 *(LONG_PTR *)(buffer+(*p))=type.GetIndex();
[4]19 (*p)+=sizeof(LONG_PTR);
20 }
21}
22
23
[75]24void GetLpIndex_DebugFile(char *buffer,int *p,Type &type){
25 if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
[4]26 char szClassName[VN_SIZE];
27 lstrcpy(szClassName,buffer+(*p));
28 (*p)+=lstrlen(buffer+(*p))+1;
29
[102]30 type.SetIndex( (LONG_PTR)pobj_DBClass->Find(szClassName) );
[4]31 }
32 else{
[75]33 type.SetIndex( *(LONG_PTR *)(buffer+(*p)) );
[4]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 //クラス名
[131]129 lstrcpy(buffer+i2,pobj_c->GetName().c_str());
[4]130 i2+=lstrlen(buffer+i2)+1;
131 }
132
133
134
135 //////////////////
136 // TypeDef情報
137 //////////////////
[88]138 *(long *)(buffer+i2)=(int)Smoothie::Meta::typeDefs.size();
[4]139 i2+=sizeof(long);
[88]140 for(i3=0;i3<(int)Smoothie::Meta::typeDefs.size();i3++){
[113]141 lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetName().c_str() );
[4]142 i2+=lstrlen(buffer+i2)+1;
143
[88]144 lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetBaseName().c_str() );
[4]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 //グローバル変数情報
[75]156 *(long *)(buffer+i2)=(int)::globalVars.size();
[4]157 i2+=sizeof(long);
[75]158 foreach( Variable *pVar, ::globalVars ){
[4]159 //変数名
[75]160 lstrcpy(buffer+i2,pVar->GetName().c_str());
[4]161 i2+=lstrlen(buffer+i2)+1;
162
163 //型
[75]164 *(long *)(buffer+i2)=pVar->GetBasicType();
[4]165 i2+=sizeof(long);
166
167 //型の拡張情報
[75]168 SetLpIndex_DebugFile(buffer,&i2,*pVar);
[4]169
[75]170 buffer[i2++] = pVar->IsRef() ? 1 : 0;
[4]171
[75]172 buffer[i2++] = pVar->IsArray() ? 1 : 0;
[4]173
[75]174 if(pVar->IsArray()){
175 for(i5=0;;i5++){
176 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
[4]177 i2+=sizeof(long);
[75]178 if(pVar->GetSubScriptsPtr()[i5]==-1) break;
[4]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 //プロシージャ情報
[100]207 extern GlobalProc **ppSubHash;
[4]208 extern int SubNum;
[100]209 GlobalProc *pUserProc;
[4]210 *(long *)(buffer+i2)=SubNum;
211 i2+=sizeof(long);
212 for(i3=0;i3<MAX_HASH;i3++){
[75]213 pUserProc=ppSubHash[i3];
214 while(pUserProc){
215 if(pUserProc->GetParentClassPtr()){
[131]216 lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->GetName().c_str());
[4]217 i2+=lstrlen(buffer+i2)+1;
218 }
219 else{
220 lstrcpy(buffer+i2,"");
221 i2+=lstrlen(buffer+i2)+1;
222 }
223
224 //ID
[75]225 *(long *)(buffer+i2)=pUserProc->id;
[4]226 i2+=sizeof(long);
227
228 //関数名
[75]229 lstrcpy(buffer+i2,pUserProc->GetName().c_str());
[4]230 i2+=lstrlen(buffer+i2)+1;
231
[75]232 *(long *)(buffer+i2)=pUserProc->beginOpAddress;
[4]233 i2+=sizeof(long);
[75]234 *(long *)(buffer+i2)=pUserProc->endOpAddress;
[4]235 i2+=sizeof(long);
236
237 //ローカル変数情報
[75]238 *(long *)(buffer+i2)=(int)pUserProc->localVars.size();
[4]239 i2+=sizeof(long);
240
241 //バッファが足りない場合は再確保
242 if(BufferSize<i2+32768){
243 BufferSize+=32768;
244 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
245 }
246
[75]247 foreach( Variable *pVar, pUserProc->localVars ){
248 lstrcpy(buffer+i2,pVar->GetName().c_str());
[4]249 i2+=lstrlen(buffer+i2)+1;
250
251 //型
[75]252 *(long *)(buffer+i2)=pVar->GetBasicType();
[4]253 i2+=sizeof(long);
254
255 //型の拡張情報
[75]256 SetLpIndex_DebugFile(buffer,&i2,*pVar);
[4]257
258 //参照型パラメータかどうか
[75]259 buffer[i2++] = pVar->IsRef() ? 1 : 0;
[4]260
261 //配列かどうか
[75]262 buffer[i2++] = pVar->IsArray() ? 1 : 0;
[4]263
264 //配列要素
[75]265 if(pVar->IsArray()){
[4]266 for(i5=0;;i5++){
[75]267 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
[4]268 i2+=sizeof(long);
[75]269 if(pVar->GetSubScriptsPtr()[i5]==-1) break;
[4]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
[75]295 pUserProc=pUserProc->pNextData;
[4]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 //クラス名
[131]314 lstrcpy(buffer+i2,pobj_c->GetName().c_str());
[4]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++){
[135]329 lstrcpy(buffer+i2,pobj_c->ppobj_Member[i4]->GetName().c_str());
[4]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 //型
[75]336 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetBasicType();
[4]337 i2+=sizeof(long);
338
339 //型の拡張情報
[75]340 SetLpIndex_DebugFile(buffer,&i2,*pobj_c->ppobj_Member[i4]);
[4]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 //メソッド
[51]353 *(long *)(buffer+i2)=(long)pobj_c->methods.size();
[4]354 i2+=sizeof(long);
[135]355 foreach( const CMethod *pMethod, pobj_c->methods ){
356 *(long *)(buffer+i2)=pMethod->dwAccess;
[4]357 i2+=sizeof(long);
[135]358 if( pMethod->GetInheritsClassPtr() ){
359 lstrcpy(buffer+i2,pMethod->GetInheritsClassPtr()->GetName().c_str());
[4]360 i2+=lstrlen(buffer+i2)+1;
361 }
362 else{
363 lstrcpy(buffer+i2,"");
364 i2+=lstrlen(buffer+i2)+1;
365 }
[135]366 lstrcpy(buffer+i2,pMethod->pUserProc->GetName().c_str());
[4]367 i2+=lstrlen(buffer+i2)+1;
368 }
369
370 //静的メンバ
[53]371 *(long *)(buffer+i2)=(long)pobj_c->staticMembers.size();
[4]372 i2+=sizeof(long);
[53]373 foreach( CMember *member, pobj_c->staticMembers ){
[135]374 lstrcpy(buffer+i2,member->GetName().c_str());
[4]375 i2+=lstrlen(buffer+i2)+1;
376
[53]377 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
[4]378 i2+=sizeof(int)*MAX_ARRAYDIM;
379
380 //型
[75]381 *(long *)(buffer+i2)=member->GetBasicType();
[4]382 i2+=sizeof(long);
383
384 //型の拡張情報
[75]385 SetLpIndex_DebugFile(buffer,&i2,*member);
[4]386
[53]387 *(long *)(buffer+i2)=member->dwAccess;
[4]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
[114]430 pobj_CompilingClass = NULL;
[16]431
[4]432 i2=0;
433
434 //デバッグ用ファイルのバージョンをチェック
435 if(*(long *)(buffer+i2)<MDLFILE_VER){
436 HeapDefaultFree(buffer);
437 return 0;
438 }
439 i2+=sizeof(long);
440
441 //プラットフォームのビット数をチェック
442 if(*(long *)(buffer+i2)!=PLATFORM){
443 HeapDefaultFree(buffer);
444 return 0;
445 }
446 i2+=sizeof(long);
447
448 //インクルード情報
449 IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
450 i2+=sizeof(long);
451 IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *));
452 for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
453 if(buffer[i2]=='\0') break;
454 IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
455 lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2);
456 i2+=lstrlen(buffer+i2)+1;
457 }
458 for(i2++,i3=0;;i2++,i3++){
459 IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2];
460 if(IncludeFileInfo.LineOfFile[i3]==-1) break;
461 }
462
463 //ソースコード
464 i2++;
[88]465 source.SetBuffer( buffer + i2 );
[15]466 i2+=lstrlen(buffer+i2)+1;
[4]467
468 //コードと行番号の関係
469 MaxLineInfoNum=*(long *)(buffer+i2);
470 i2+=sizeof(long);
471 pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1);
472 memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO));
473 i2+=MaxLineInfoNum*sizeof(LINEINFO);
474
475
476 ///////////////////////////////////////////
477 // クラス情報(名前のみ。詳細は後で取得)
478 ///////////////////////////////////////////
479
480 this->pobj_DBClass=new CDBClass();
481
482 int iMaxClassCount;
483 iMaxClassCount=*(long *)(buffer+i2);
484 i2+=sizeof(long);
485 for(i3=0;i3<iMaxClassCount;i3++){
486 //クラス名
[101]487 // TODO: 名前空間が未完成
[108]488 pobj_DBClass->AddClass(NamespaceScopes(),NamespaceScopesCollection(),buffer+i2,0);
[4]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 //初期化
[88]501 Smoothie::Meta::typeDefs.clear();
[4]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
[113]510 // 名前空間に未対応
511 Smoothie::Meta::typeDefs.push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2 ) );
[4]512
513 i2+=lstrlen(buffer+i2)+1;
514 }
515
516 //定数を取得
517 GetConstInfo();
518 extern CONSTINFO **ppConstHash;
519 this->ppConstHash=ppConstHash;
520
521
522 //グローバル変数情報
[75]523 globalVars.clear();
524 int maxGlobalVars=*(long *)(buffer+i2);
[4]525 i2+=sizeof(long);
[75]526 for(i3=0;i3<maxGlobalVars;i3++){
[4]527
528 //変数名
[75]529 char *name = buffer+i2;
[4]530 i2+=lstrlen(buffer+i2)+1;
531
[75]532 int basicType = *(long *)(buffer+i2);
[4]533 i2+=sizeof(long);
534
[75]535 Type type( basicType );
536 GetLpIndex_DebugFile(buffer,&i2,type);
[4]537
[75]538 bool isRef = (buffer[i2++]) ? true:false;
[4]539
[75]540 bool isArray = (buffer[i2++]) ? true:false;
541
542 Variable *pVar = new Variable( name, type, false, isRef );
543
544 if(isArray){
545 int SubScripts[MAX_ARRAYDIM];
[4]546 for(i4=0;;i4++){
[75]547 SubScripts[i4]=*(long *)(buffer+i2);
[4]548 i2+=sizeof(long);
549
[75]550 if(SubScripts[i4]==-1) break;
[4]551 }
[75]552
553 pVar->SetArray( SubScripts );
[4]554 }
555
556 //レキシカルスコープ情報
557 pVar->ScopeStartAddress=*(long *)(buffer+i2);
558 i2+=sizeof(long);
559 pVar->ScopeEndAddress=*(long *)(buffer+i2);
560 i2+=sizeof(long);
561 pVar->ScopeLevel=*(long *)(buffer+i2);
562 i2+=sizeof(long);
563
564 //メモリ位置
565 pVar->offset=*(long *)(buffer+i2);
566 i2+=sizeof(long);
[75]567
568 //変数を追加
569 globalVars.push_back( pVar );
[4]570 }
571
572 //グローバル実行領域のサイズ
573 GlobalOpBufferSize=*(long *)(buffer+i2);
574 i2+=sizeof(long);
575
576 //プロシージャ情報
[100]577 GlobalProc *pUserProc;
[4]578 SubNum=*(long *)(buffer+i2);
579 i2+=sizeof(long);
[100]580 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
[75]581 for(int i6=0;i6<SubNum;i6++){
[4]582 char szParentClassName[VN_SIZE];
583 lstrcpy(szParentClassName,buffer+i2);
584 i2+=lstrlen(buffer+i2)+1;
585
[114]586 const CClass *pClass = NULL;
587 if(szParentClassName[0]){
[102]588 pClass=pobj_DBClass->Find(szParentClassName);
[114]589 }
[4]590
591 //ID
[75]592 int id=*(long *)(buffer+i2);
[4]593 i2+=sizeof(long);
594
595 //名前
[75]596 char *name = buffer+i2;
[4]597 i2+=lstrlen(buffer+i2)+1;
598
[75]599 // オブジェクトを生成
[100]600 // TODO: 名前空間が未完成
[108]601 pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false );
[75]602 pUserProc->pNextData=0;
603 pUserProc->id=id;
604 pUserProc->SetParentClass( pClass );
605
606 pUserProc->beginOpAddress=*(long *)(buffer+i2);
[4]607 i2+=sizeof(long);
[75]608 pUserProc->endOpAddress=*(long *)(buffer+i2);
[4]609 i2+=sizeof(long);
610
[75]611 pUserProc->CompleteCompile();
[4]612
613 //ローカル変数情報
[75]614 pUserProc->localVars.clear();
615 int maxLocalVar=*(long *)(buffer+i2);
[4]616 i2+=sizeof(long);
[75]617 for(i3=0;i3<maxLocalVar;i3++){
618 //変数名
619 char *name = buffer+i2;
[4]620 i2+=lstrlen(buffer+i2)+1;
621
[75]622 int basicType = *(long *)(buffer+i2);
[4]623 i2+=sizeof(long);
624
[75]625 Type type( basicType );
626 GetLpIndex_DebugFile(buffer,&i2,type);
[4]627
[75]628 bool isRef = (buffer[i2++]) ? true:false;
[4]629
[75]630 bool isArray = (buffer[i2++]) ? true:false;
631
632 Variable *pVar = new Variable( name, type, false, isRef );
633
634 if(isArray){
635 int SubScripts[MAX_ARRAYDIM];
636 for(i4=0;;i4++){
637 SubScripts[i4]=*(long *)(buffer+i2);
[4]638 i2+=sizeof(long);
639
[75]640 if(SubScripts[i4]==-1) break;
[4]641 }
[75]642
643 pVar->SetArray( SubScripts );
[4]644 }
645
646 //レキシカルスコープ情報
647 pVar->ScopeStartAddress=*(long *)(buffer+i2);
648 i2+=sizeof(long);
649 pVar->ScopeEndAddress=*(long *)(buffer+i2);
650 i2+=sizeof(long);
651 pVar->ScopeLevel=*(long *)(buffer+i2);
652 i2+=sizeof(long);
653
[75]654 //メモリ位置
[4]655 pVar->offset=*(long *)(buffer+i2);
656 i2+=sizeof(long);
[75]657
658 //変数を追加
659 pUserProc->localVars.push_back( pVar );
[4]660 }
661
662
663 /////////////////////////////////
[75]664 // 格納位置を計算してpUserProcをセット
[4]665 /////////////////////////////////
666
[75]667 i4=hash_default(pUserProc->GetName().c_str());
[4]668
[100]669 GlobalProc *psi2;
[4]670 if(ppSubHash[i4]){
671 psi2=ppSubHash[i4];
672 while(1){
673 if(psi2->pNextData==0){
[75]674 psi2->pNextData=pUserProc;
[4]675 break;
676 }
677 psi2=psi2->pNextData;
678 }
679 }
680 else{
[75]681 ppSubHash[i4]=pUserProc;
[4]682 }
683 }
684
685 //クラス情報
686 CClass *pobj_c;
687 for(i3=0;i3<iMaxClassCount;i3++){
688 //クラス名
689 char szClassName[VN_SIZE];
690 lstrcpy(szClassName,buffer+i2);
691 i2+=lstrlen(buffer+i2)+1;
692
[114]693 pobj_c = const_cast<CClass *>( pobj_DBClass->Find(szClassName) );
[4]694
695 //仮想関数の数
696 pobj_c->vtbl_num=*(long *)(buffer+i2);
697 i2+=sizeof(long);
698
699 //アラインメント
700 pobj_c->iAlign=*(long *)(buffer+i2);
701 i2+=sizeof(long);
702
703 //メンバ
704 pobj_c->iMemberNum=*(long *)(buffer+i2);
705 i2+=sizeof(long);
706 pobj_c->ppobj_Member=
707 (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *));
708 for(i4=0;i4<pobj_c->iMemberNum;i4++){
709 pobj_c->ppobj_Member[i4]=new CMember();
710
[135]711 pobj_c->ppobj_Member[i4]->SetName( (char *)(buffer+i2) );
[4]712 i2+=lstrlen(buffer+i2)+1;
713
714 memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
715 i2+=sizeof(int)*MAX_ARRAYDIM;
716
717 //型
[75]718 Type type( *(long *)(buffer+i2) );
[4]719 i2+=sizeof(long);
720
721 //型の拡張情報
[75]722 GetLpIndex_DebugFile(buffer,&i2,type);
[4]723
[75]724 pobj_c->ppobj_Member[i4]->SetType( type.GetBasicType(), type.GetIndex() );
725
[4]726 pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2);
727 i2+=sizeof(long);
728 }
729
730 //メソッド
[51]731 int nMethod = *(long *)(buffer+i2);
[4]732 i2+=sizeof(long);
[51]733 for( i4=0; i4<nMethod; i4++ ){
[4]734
[100]735 DWORD dwAccess=*(long *)(buffer+i2);
[4]736 i2+=sizeof(long);
737
738 char szInherits[VN_SIZE];
739 lstrcpy(szInherits,buffer+i2);
740 i2+=lstrlen(buffer+i2)+1;
741
[114]742 const CClass *pobj_InheritsClass = NULL;
[100]743 if(szInherits[0]){
[102]744 pobj_InheritsClass=pobj_DBClass->Find(szInherits);
[100]745 }
[4]746
747 lstrcpy(temp2,buffer+i2);
748 i2+=lstrlen(buffer+i2)+1;
749
[114]750 const CClass *pobj_temp_c;
[100]751 pobj_temp_c=pobj_InheritsClass;
[4]752 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
753 i5=hash_default(temp2);
[75]754 pUserProc=ppSubHash[i5];
[4]755 while(1){
[75]756 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
757 pUserProc=pUserProc->pNextData;
[4]758 }
[51]759
[135]760 CMethod *pMethod = new DynamicMethod( pUserProc, dwAccess, 0,0,false, pobj_InheritsClass);
[100]761
[135]762 pobj_c->methods.push_back( pMethod );
[4]763 }
764
765 //静的メンバ
[53]766 int nStaticMember = *(long *)(buffer+i2);
[4]767 i2+=sizeof(long);
[53]768 for( i4=0; i4<nStaticMember; i4++ ){
769 CMember *member=new CMember();
[4]770
[135]771 member->SetName( (char *)(buffer+i2) );
[4]772 i2+=lstrlen(buffer+i2)+1;
773
[53]774 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
[4]775 i2+=sizeof(int)*MAX_ARRAYDIM;
776
777 //型
[75]778 Type type( *(long *)(buffer+i2) );
[4]779 i2+=sizeof(long);
780
781 //型の拡張情報
[75]782 GetLpIndex_DebugFile(buffer,&i2,type);
[4]783
[75]784 member->SetType( type.GetBasicType(), type.GetIndex() );
785
[53]786 member->dwAccess=*(long *)(buffer+i2);
[4]787 i2+=sizeof(long);
[53]788
789 pobj_c->staticMembers.push_back( member );
[4]790 }
791 }
792
793 HeapDefaultFree(buffer);
794 buffer=0;
795
796
797
798
[100]799 extern GlobalProc **ppSubHash;
[4]800 ppSubHash=this->ppSubHash;
801 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
802
803
804 SingleStepCodeBuffer=MakeSingleStepCode();
805
806
807 /////////////////////////////
808 // ブレークポイントを適用
809 /////////////////////////////
810
811 //インクルード情報
812 extern INCLUDEFILEINFO IncludeFileInfo;
813 IncludeFileInfo=this->IncludeFileInfo;
814
815 //コードと行番号の関係
816 extern int MaxLineInfoNum;
817 extern LINEINFO *pLineInfo;
818 MaxLineInfoNum=this->MaxLineInfoNum;
819 pLineInfo=this->pLineInfo;
820
821 BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
822
823 //プロセスメモリにコピー
824 extern HANDLE hDebugProcess;
[76]825 SIZE_T accessBytes;
[4]826 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
827 BreakStepCodeBuffer,
[76]828 SizeOf_CodeSection,&accessBytes);
[4]829
830
831 return 1;
832}
833
834BOOL CDebugSection::load(HMODULE hModule){
835 if(buffer){
836 HeapDefaultFree(buffer);
837 buffer=0;
838 }
839
840
841 extern HANDLE hDebugProcess;
[76]842 SIZE_T accessBytes;
[4]843 IMAGE_DOS_HEADER ImageDosHeader;
[76]844 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes);
[4]845
846 int pe_size;
847#ifdef _AMD64_
848 IMAGE_NT_HEADERS64 pe_hdr;
849 pe_size=sizeof(IMAGE_NT_HEADERS64);
850#else
851 IMAGE_NT_HEADERS pe_hdr;
852 pe_size=sizeof(IMAGE_NT_HEADERS);
853#endif
[76]854 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes);
[4]855
856 IMAGE_SECTION_HEADER *pSectionHdr;
857 pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
858 ReadProcessMemory(hDebugProcess,
859 (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
860 pSectionHdr,
861 pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
[76]862 &accessBytes);
[4]863
864 int i;
865 for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
866
867 //リライタブルセクション内の情報
868 if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
869 dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
870 }
871
872 //コードセクション内の情報
873 if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
874 dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
875 SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
876 }
877
878 //デバッグセクション内の情報
879 if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
880 length=pSectionHdr[i].Misc.VirtualSize;
881 buffer=(char *)HeapAlloc(hHeap,0,length+1);
882
883 ReadProcessMemory(hDebugProcess,
884 (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
885 buffer,
886 length,
[76]887 &accessBytes);
[4]888 buffer[length]=0;
889 }
890
891 }
892 HeapDefaultFree(pSectionHdr);
893
894 if(!buffer) return 0;
895
896
897 dwImageBase=(DWORD)(ULONG_PTR)hModule;
898
899
900
901 if(OpBuffer) HeapDefaultFree(OpBuffer);
902 OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
903
904 ReadProcessMemory(hDebugProcess,
905 (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
[76]906 SizeOf_CodeSection,&accessBytes);
[4]907
908
909 return __load();
910}
911
912void CDebugSection::choice(void){
913 //イメージベース
914 extern DWORD ImageBase;
915 ImageBase=this->dwImageBase;
916
917 //リライタブルセクションのRVA
918 extern int MemPos_RWSection;
919 MemPos_RWSection=this->dwRVA_RWSection;
920
921 //コードセクションのRVAとサイズ
922 extern int MemPos_CodeSection;
923 extern int FileSize_CodeSection;
924 MemPos_CodeSection=this->dwRVA_CodeSection;
925 FileSize_CodeSection=this->SizeOf_CodeSection;
926
927 //インクルード情報
928 extern INCLUDEFILEINFO IncludeFileInfo;
929 IncludeFileInfo=this->IncludeFileInfo;
930
931 //ソースコード
[88]932 Smoothie::Lexical::source = source;
[4]933
934 //コードと行番号の関係
935 extern int MaxLineInfoNum;
936 extern LINEINFO *pLineInfo;
937 MaxLineInfoNum=this->MaxLineInfoNum;
938 pLineInfo=this->pLineInfo;
939
940 // クラス情報
941 extern CDBClass *pobj_DBClass;
942 pobj_DBClass=this->pobj_DBClass;
943
944 //定数を取得
945 extern CONSTINFO **ppConstHash;
946 ppConstHash=this->ppConstHash;
947
948 //グローバル実行領域のサイズ
949 extern int GlobalOpBufferSize;
950 GlobalOpBufferSize=this->GlobalOpBufferSize;
951
952 //プロシージャ
953 extern char **ppMacroNames;
954 ppMacroNames=0;
[100]955 extern GlobalProc **ppSubHash;
[4]956 extern int SubNum;
957 ppSubHash=this->ppSubHash;
958 SubNum=this->SubNum;
959
[75]960 extern UserProc *pSub_DebugSys_EndProc;
[4]961 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
962
963 //ネイティブコードバッファ
964 extern char *OpBuffer;
965 OpBuffer=this->OpBuffer;
966}
967
968void CDebugSection::DeleteDebugInfo(void){
969 int i2;
970
971 //インクルード情報を解放
972 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
973 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
974 HeapDefaultFree(IncludeFileInfo.ppFileNames);
975
976 //クラスに関するメモリを解放
977 delete pobj_DBClass;
978 pobj_DBClass=0;
979
980 //サブルーチン情報のメモリ解放
981 DeleteSubInfo(ppSubHash,0,0);
982
983 //定数に関する情報を解放
984 DeleteConstInfo(ppConstHash);
985
986 //コードと行番号の関係を解放
987 HeapDefaultFree(pLineInfo);
988
989 //コードバッファを解放
990 HeapDefaultFree(OpBuffer);
991 OpBuffer=0;
992
993 HeapDefaultFree(SingleStepCodeBuffer);
994 SingleStepCodeBuffer=0;
995
996 HeapDefaultFree(BreakStepCodeBuffer);
997 BreakStepCodeBuffer=0;
998}
999
1000
1001
1002CDBDebugSection::CDBDebugSection(){
1003 ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
1004 num=0;
1005}
1006CDBDebugSection::~CDBDebugSection(){
1007 int i;
1008 for(i=0;i<num;i++){
1009 delete ppobj_ds[i];
1010 }
1011 HeapDefaultFree(ppobj_ds);
1012}
1013
1014BOOL CDBDebugSection::add(HMODULE hModule){
1015 CDebugSection *pobj_d;
1016 pobj_d=new CDebugSection();
1017 if(!pobj_d->load(hModule)){
1018 //デバッグ情報が存在しないとき
1019 delete pobj_d;
1020 return 0;
1021 }
1022
1023 ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
1024 ppobj_ds[num]=pobj_d;
1025 num++;
1026
1027 return 1;
1028}
1029
1030void CDBDebugSection::del(HMODULE hModule){
1031 int i;
1032 for(i=0;i<num;i++){
1033 if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
1034 delete ppobj_ds[i];
1035
1036 num--;
1037 for(;i<num;i++){
1038 ppobj_ds[i]=ppobj_ds[i+1];
1039 }
1040 break;
1041 }
1042 }
1043}
1044
1045void CDBDebugSection::choice(int index){
1046 pobj_now=ppobj_ds[index];
1047 pobj_now->choice();
1048}
1049
1050
1051
1052CDBDebugSection *pobj_DBDebugSection;
Note: See TracBrowser for help on using the repository browser.