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

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