source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 100

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

名前空間機能をグローバル関数に適用。

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