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
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++){
[137]329 // 名前
[135]330 lstrcpy(buffer+i2,pobj_c->ppobj_Member[i4]->GetName().c_str());
[4]331 i2+=lstrlen(buffer+i2)+1;
332
[137]333 // 型
334 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetType().GetBasicType();
[4]335 i2+=sizeof(long);
336
[137]337 // 型の拡張情報
338 SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->GetType());
[4]339
[137]340 // アクセシビリティ
341 *(Prototype::Accessibility *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetAccessibility();
342 i2+=sizeof(Prototype::Accessibility);
[4]343
[137]344 memcpy(buffer+i2,pobj_c->ppobj_Member[i4]->SubScripts,sizeof(int)*MAX_ARRAYDIM);
345 i2+=sizeof(int)*MAX_ARRAYDIM;
346
[4]347 //バッファが足りない場合は再確保
348 if(BufferSize<i2+32768){
349 BufferSize+=32768;
350 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
351 }
352 }
353
354 //メソッド
[51]355 *(long *)(buffer+i2)=(long)pobj_c->methods.size();
[4]356 i2+=sizeof(long);
[135]357 foreach( const CMethod *pMethod, pobj_c->methods ){
[137]358 *(Prototype::Accessibility *)(buffer+i2)=pMethod->GetAccessibility();
359 i2+=sizeof(Prototype::Accessibility);
[135]360 if( pMethod->GetInheritsClassPtr() ){
361 lstrcpy(buffer+i2,pMethod->GetInheritsClassPtr()->GetName().c_str());
[4]362 i2+=lstrlen(buffer+i2)+1;
363 }
364 else{
365 lstrcpy(buffer+i2,"");
366 i2+=lstrlen(buffer+i2)+1;
367 }
[135]368 lstrcpy(buffer+i2,pMethod->pUserProc->GetName().c_str());
[4]369 i2+=lstrlen(buffer+i2)+1;
370 }
371
372 //静的メンバ
[53]373 *(long *)(buffer+i2)=(long)pobj_c->staticMembers.size();
[4]374 i2+=sizeof(long);
[53]375 foreach( CMember *member, pobj_c->staticMembers ){
[137]376 // 名前
[135]377 lstrcpy(buffer+i2,member->GetName().c_str());
[4]378 i2+=lstrlen(buffer+i2)+1;
379
[137]380 // 型
381 *(long *)(buffer+i2)=member->GetType().GetBasicType();
[4]382 i2+=sizeof(long);
383
[137]384 // 型の拡張情報
385 SetLpIndex_DebugFile(buffer,&i2,member->GetType());
[4]386
[137]387 // アクセシビリティ
388 *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
389 i2+=sizeof(Prototype::Accessibility);
[4]390
[137]391 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
392 i2+=sizeof(int)*MAX_ARRAYDIM;
393
[4]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
[114]434 pobj_CompilingClass = NULL;
[16]435
[4]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++;
[88]469 source.SetBuffer( buffer + i2 );
[15]470 i2+=lstrlen(buffer+i2)+1;
[4]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 //クラス名
[101]491 // TODO: 名前空間が未完成
[108]492 pobj_DBClass->AddClass(NamespaceScopes(),NamespaceScopesCollection(),buffer+i2,0);
[4]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 //初期化
[88]505 Smoothie::Meta::typeDefs.clear();
[4]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
[113]514 // 名前空間に未対応
515 Smoothie::Meta::typeDefs.push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2 ) );
[4]516
517 i2+=lstrlen(buffer+i2)+1;
518 }
519
520 //定数を取得
521 GetConstInfo();
522 extern CONSTINFO **ppConstHash;
523 this->ppConstHash=ppConstHash;
524
525
526 //グローバル変数情報
[75]527 globalVars.clear();
528 int maxGlobalVars=*(long *)(buffer+i2);
[4]529 i2+=sizeof(long);
[75]530 for(i3=0;i3<maxGlobalVars;i3++){
[4]531
532 //変数名
[75]533 char *name = buffer+i2;
[4]534 i2+=lstrlen(buffer+i2)+1;
535
[75]536 int basicType = *(long *)(buffer+i2);
[4]537 i2+=sizeof(long);
538
[75]539 Type type( basicType );
540 GetLpIndex_DebugFile(buffer,&i2,type);
[4]541
[75]542 bool isRef = (buffer[i2++]) ? true:false;
[4]543
[75]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];
[4]550 for(i4=0;;i4++){
[75]551 SubScripts[i4]=*(long *)(buffer+i2);
[4]552 i2+=sizeof(long);
553
[75]554 if(SubScripts[i4]==-1) break;
[4]555 }
[75]556
557 pVar->SetArray( SubScripts );
[4]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);
[75]571
572 //変数を追加
573 globalVars.push_back( pVar );
[4]574 }
575
576 //グローバル実行領域のサイズ
577 GlobalOpBufferSize=*(long *)(buffer+i2);
578 i2+=sizeof(long);
579
580 //プロシージャ情報
[100]581 GlobalProc *pUserProc;
[4]582 SubNum=*(long *)(buffer+i2);
583 i2+=sizeof(long);
[100]584 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
[75]585 for(int i6=0;i6<SubNum;i6++){
[4]586 char szParentClassName[VN_SIZE];
587 lstrcpy(szParentClassName,buffer+i2);
588 i2+=lstrlen(buffer+i2)+1;
589
[114]590 const CClass *pClass = NULL;
591 if(szParentClassName[0]){
[102]592 pClass=pobj_DBClass->Find(szParentClassName);
[114]593 }
[4]594
595 //ID
[75]596 int id=*(long *)(buffer+i2);
[4]597 i2+=sizeof(long);
598
599 //名前
[75]600 char *name = buffer+i2;
[4]601 i2+=lstrlen(buffer+i2)+1;
602
[75]603 // オブジェクトを生成
[100]604 // TODO: 名前空間が未完成
[108]605 pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false );
[75]606 pUserProc->pNextData=0;
607 pUserProc->id=id;
608 pUserProc->SetParentClass( pClass );
609
610 pUserProc->beginOpAddress=*(long *)(buffer+i2);
[4]611 i2+=sizeof(long);
[75]612 pUserProc->endOpAddress=*(long *)(buffer+i2);
[4]613 i2+=sizeof(long);
614
[75]615 pUserProc->CompleteCompile();
[4]616
617 //ローカル変数情報
[75]618 pUserProc->localVars.clear();
619 int maxLocalVar=*(long *)(buffer+i2);
[4]620 i2+=sizeof(long);
[75]621 for(i3=0;i3<maxLocalVar;i3++){
622 //変数名
623 char *name = buffer+i2;
[4]624 i2+=lstrlen(buffer+i2)+1;
625
[75]626 int basicType = *(long *)(buffer+i2);
[4]627 i2+=sizeof(long);
628
[75]629 Type type( basicType );
630 GetLpIndex_DebugFile(buffer,&i2,type);
[4]631
[75]632 bool isRef = (buffer[i2++]) ? true:false;
[4]633
[75]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);
[4]642 i2+=sizeof(long);
643
[75]644 if(SubScripts[i4]==-1) break;
[4]645 }
[75]646
647 pVar->SetArray( SubScripts );
[4]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
[75]658 //メモリ位置
[4]659 pVar->offset=*(long *)(buffer+i2);
660 i2+=sizeof(long);
[75]661
662 //変数を追加
663 pUserProc->localVars.push_back( pVar );
[4]664 }
665
666
667 /////////////////////////////////
[75]668 // 格納位置を計算してpUserProcをセット
[4]669 /////////////////////////////////
670
[75]671 i4=hash_default(pUserProc->GetName().c_str());
[4]672
[100]673 GlobalProc *psi2;
[4]674 if(ppSubHash[i4]){
675 psi2=ppSubHash[i4];
676 while(1){
677 if(psi2->pNextData==0){
[75]678 psi2->pNextData=pUserProc;
[4]679 break;
680 }
681 psi2=psi2->pNextData;
682 }
683 }
684 else{
[75]685 ppSubHash[i4]=pUserProc;
[4]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
[114]697 pobj_c = const_cast<CClass *>( pobj_DBClass->Find(szClassName) );
[4]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
[137]714 // 名前
715 string name = (char *)(buffer+i2);
[4]716 i2+=lstrlen(buffer+i2)+1;
717
[137]718 // 型
[75]719 Type type( *(long *)(buffer+i2) );
[4]720 i2+=sizeof(long);
721
[137]722 // 型の拡張情報
[75]723 GetLpIndex_DebugFile(buffer,&i2,type);
[4]724
[137]725 // アクセシビリティ
726 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
727 i2+=sizeof(Prototype::Accessibility);
[75]728
[137]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;
[4]733 }
734
735 //メソッド
[51]736 int nMethod = *(long *)(buffer+i2);
[4]737 i2+=sizeof(long);
[51]738 for( i4=0; i4<nMethod; i4++ ){
[4]739
[137]740 Prototype::Accessibility accessibility=*(Prototype::Accessibility *)(buffer+i2);
741 i2+=sizeof(Prototype::Accessibility);
[4]742
743 char szInherits[VN_SIZE];
744 lstrcpy(szInherits,buffer+i2);
745 i2+=lstrlen(buffer+i2)+1;
746
[114]747 const CClass *pobj_InheritsClass = NULL;
[100]748 if(szInherits[0]){
[102]749 pobj_InheritsClass=pobj_DBClass->Find(szInherits);
[100]750 }
[4]751
752 lstrcpy(temp2,buffer+i2);
753 i2+=lstrlen(buffer+i2)+1;
754
[114]755 const CClass *pobj_temp_c;
[100]756 pobj_temp_c=pobj_InheritsClass;
[4]757 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
758 i5=hash_default(temp2);
[75]759 pUserProc=ppSubHash[i5];
[4]760 while(1){
[75]761 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
762 pUserProc=pUserProc->pNextData;
[4]763 }
[51]764
[137]765 CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, 0,0,false, pobj_InheritsClass);
[100]766
[135]767 pobj_c->methods.push_back( pMethod );
[4]768 }
769
770 //静的メンバ
[53]771 int nStaticMember = *(long *)(buffer+i2);
[4]772 i2+=sizeof(long);
[53]773 for( i4=0; i4<nStaticMember; i4++ ){
[137]774 // 名前
775 string name = (char *)(buffer+i2);
[4]776 i2+=lstrlen(buffer+i2)+1;
777
[137]778 // 型
[75]779 Type type( *(long *)(buffer+i2) );
[4]780 i2+=sizeof(long);
781
[137]782 // 型の拡張情報
[75]783 GetLpIndex_DebugFile(buffer,&i2,type);
[4]784
[137]785 // アクセシビリティ
786 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
787 i2+=sizeof(Prototype::Accessibility);
[75]788
[137]789 CMember *member=new CMember( accessibility, name, type, false );
[53]790
[137]791 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
792 i2+=sizeof(int)*MAX_ARRAYDIM;
793
[53]794 pobj_c->staticMembers.push_back( member );
[4]795 }
796 }
797
798 HeapDefaultFree(buffer);
799 buffer=0;
800
801
802
803
[100]804 extern GlobalProc **ppSubHash;
[4]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;
[76]830 SIZE_T accessBytes;
[4]831 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
832 BreakStepCodeBuffer,
[76]833 SizeOf_CodeSection,&accessBytes);
[4]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;
[76]847 SIZE_T accessBytes;
[4]848 IMAGE_DOS_HEADER ImageDosHeader;
[76]849 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes);
[4]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
[76]859 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes);
[4]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),
[76]867 &accessBytes);
[4]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,
[76]892 &accessBytes);
[4]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,
[76]911 SizeOf_CodeSection,&accessBytes);
[4]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 //ソースコード
[88]937 Smoothie::Lexical::source = source;
[4]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;
[100]960 extern GlobalProc **ppSubHash;
[4]961 extern int SubNum;
962 ppSubHash=this->ppSubHash;
963 SubNum=this->SubNum;
964
[75]965 extern UserProc *pSub_DebugSys_EndProc;
[4]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.