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

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