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

Last change on this file since 201 was 201, checked in by dai_9181, 17 years ago
File size: 25.4 KB
Line 
1#include <jenga/include/smoothie/Smoothie.h>
2
3#include <Compiler.h>
4#include <ClassImpl.h>
5#include <VariableImpl.h>
6
7#include "../BasicCompiler_Common/common.h"
8
9#ifdef _AMD64_
10#include "../BasicCompiler64/opcode.h"
11#else
12#include "../BasicCompiler32/opcode.h"
13#endif
14
15#define MDLFILE_VER 0x70000003
16
17
18void SetLpIndex_DebugFile(char *buffer,int *p,const Type &type){
19 if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
20 lstrcpy(buffer+(*p),type.GetClass().GetName().c_str());
21 (*p)+=lstrlen(buffer+(*p))+1;
22 }
23 else{
24 *(LONG_PTR *)(buffer+(*p))=type.GetIndex();
25 (*p)+=sizeof(LONG_PTR);
26 }
27}
28
29
30void GetLpIndex_DebugFile(char *buffer,int *p,Type &type){
31 if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
32 char szClassName[VN_SIZE];
33 lstrcpy(szClassName,buffer+(*p));
34 (*p)+=lstrlen(buffer+(*p))+1;
35
36 type.SetClassPtr( compiler.GetMeta().GetClasses().Find(szClassName) );
37 }
38 else{
39 type.SetIndex( *(LONG_PTR *)(buffer+(*p)) );
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;
58 int i2,i3,i5,BufferSize;
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 //イテレータをリセット
123 compiler.GetMeta().GetClasses().Iterator_Reset();
124
125 //個数
126 *(long *)(buffer+i2)=compiler.GetMeta().GetClasses().Iterator_GetMaxCount();
127 i2+=sizeof(long);
128
129 while(compiler.GetMeta().GetClasses().Iterator_HasNext()){
130 CClass *pobj_c;
131 pobj_c=compiler.GetMeta().GetClasses().Iterator_GetNext();
132
133 //クラス名
134 lstrcpy(buffer+i2,pobj_c->GetName().c_str());
135 i2+=lstrlen(buffer+i2)+1;
136 }
137
138
139
140 //////////////////
141 // TypeDef情報
142 //////////////////
143 *(long *)(buffer+i2)=(int)compiler.GetMeta().GetTypeDefs().size();
144 i2+=sizeof(long);
145 for(i3=0;i3<(int)compiler.GetMeta().GetTypeDefs().size();i3++){
146 lstrcpy(buffer+i2,compiler.GetMeta().GetTypeDefs()[i3].GetName().c_str() );
147 i2+=lstrlen(buffer+i2)+1;
148
149 lstrcpy(buffer+i2,compiler.GetMeta().GetTypeDefs()[i3].GetBaseName().c_str() );
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 //グローバル変数情報
161 *(long *)(buffer+i2)=(int)::globalVars.size();
162 i2+=sizeof(long);
163 BOOST_FOREACH( Variable *pVar, ::globalVars ){
164 //変数名
165 lstrcpy(buffer+i2,pVar->GetName().c_str());
166 i2+=lstrlen(buffer+i2)+1;
167
168 //型
169 *(long *)(buffer+i2)=pVar->GetBasicType();
170 i2+=sizeof(long);
171
172 //型の拡張情報
173 SetLpIndex_DebugFile(buffer,&i2,*pVar);
174
175 buffer[i2++] = pVar->IsRef() ? 1 : 0;
176
177 buffer[i2++] = pVar->IsArray() ? 1 : 0;
178
179 if(pVar->IsArray()){
180 for(i5=0;;i5++){
181 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
182 i2+=sizeof(long);
183 if(pVar->GetSubScriptsPtr()[i5]==-1) break;
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 //プロシージャ情報
212 extern GlobalProc **ppSubHash;
213 extern int SubNum;
214 GlobalProc *pUserProc;
215 *(long *)(buffer+i2)=SubNum;
216 i2+=sizeof(long);
217 for(i3=0;i3<MAX_HASH;i3++){
218 pUserProc=ppSubHash[i3];
219 while(pUserProc){
220 if(pUserProc->GetParentClassPtr()){
221 lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->GetName().c_str());
222 i2+=lstrlen(buffer+i2)+1;
223 }
224 else{
225 lstrcpy(buffer+i2,"");
226 i2+=lstrlen(buffer+i2)+1;
227 }
228
229 //ID
230 *(long *)(buffer+i2)=pUserProc->id;
231 i2+=sizeof(long);
232
233 //関数名
234 lstrcpy(buffer+i2,pUserProc->GetName().c_str());
235 i2+=lstrlen(buffer+i2)+1;
236
237 *(long *)(buffer+i2)=pUserProc->beginOpAddress;
238 i2+=sizeof(long);
239 *(long *)(buffer+i2)=pUserProc->endOpAddress;
240 i2+=sizeof(long);
241
242 //ローカル変数情報
243 *(long *)(buffer+i2)=(int)pUserProc->localVars.size();
244 i2+=sizeof(long);
245
246 //バッファが足りない場合は再確保
247 if(BufferSize<i2+32768){
248 BufferSize+=32768;
249 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
250 }
251
252 BOOST_FOREACH( Variable *pVar, pUserProc->localVars ){
253 lstrcpy(buffer+i2,pVar->GetName().c_str());
254 i2+=lstrlen(buffer+i2)+1;
255
256 //型
257 *(long *)(buffer+i2)=pVar->GetBasicType();
258 i2+=sizeof(long);
259
260 //型の拡張情報
261 SetLpIndex_DebugFile(buffer,&i2,*pVar);
262
263 //参照型パラメータかどうか
264 buffer[i2++] = pVar->IsRef() ? 1 : 0;
265
266 //配列かどうか
267 buffer[i2++] = pVar->IsArray() ? 1 : 0;
268
269 //配列要素
270 if(pVar->IsArray()){
271 for(i5=0;;i5++){
272 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
273 i2+=sizeof(long);
274 if(pVar->GetSubScriptsPtr()[i5]==-1) break;
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
300 pUserProc=pUserProc->pNextData;
301 }
302 }
303
304
305
306 ///////////////////
307 // クラス情報
308 ///////////////////
309
310 //イテレータをリセット
311 compiler.GetMeta().GetClasses().Iterator_Reset();
312
313 while(compiler.GetMeta().GetClasses().Iterator_HasNext()){
314 CClass *pobj_c;
315 pobj_c=compiler.GetMeta().GetClasses().Iterator_GetNext();
316
317
318 //クラス名
319 lstrcpy(buffer+i2,pobj_c->GetName().c_str());
320 i2+=lstrlen(buffer+i2)+1;
321
322 //仮想関数の数
323 *(long *)(buffer+i2)=pobj_c->GetVtblNum();
324 i2+=sizeof(long);
325
326 //アラインメント
327 *(long *)(buffer+i2)=pobj_c->iAlign;
328 i2+=sizeof(long);
329
330 //メンバ
331 *(long *)(buffer+i2)=(int)pobj_c->GetDynamicMembers().size();
332 i2+=sizeof(long);
333 BOOST_FOREACH( CMember *member, pobj_c->GetDynamicMembers() ){
334 // 名前
335 lstrcpy(buffer+i2,member->GetName().c_str());
336 i2+=lstrlen(buffer+i2)+1;
337
338 // 型
339 *(long *)(buffer+i2)=member->GetType().GetBasicType();
340 i2+=sizeof(long);
341
342 // 型の拡張情報
343 SetLpIndex_DebugFile(buffer,&i2,member->GetType());
344
345 // アクセシビリティ
346 *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
347 i2+=sizeof(Prototype::Accessibility);
348
349 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
350 i2+=sizeof(int)*MAX_ARRAYDIM;
351
352 //バッファが足りない場合は再確保
353 if(BufferSize<i2+32768){
354 BufferSize+=32768;
355 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
356 }
357 }
358
359 //メソッド
360 *(long *)(buffer+i2)=(long)pobj_c->GetMethods().size();
361 i2+=sizeof(long);
362 BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetMethods() ){
363 *(Prototype::Accessibility *)(buffer+i2)=pMethod->GetAccessibility();
364 i2+=sizeof(Prototype::Accessibility);
365 if( pMethod->GetInheritsClassPtr() ){
366 lstrcpy(buffer+i2,pMethod->GetInheritsClassPtr()->GetName().c_str());
367 i2+=lstrlen(buffer+i2)+1;
368 }
369 else{
370 lstrcpy(buffer+i2,"");
371 i2+=lstrlen(buffer+i2)+1;
372 }
373 lstrcpy(buffer+i2,pMethod->pUserProc->GetName().c_str());
374 i2+=lstrlen(buffer+i2)+1;
375 }
376
377 //静的メンバ
378 *(long *)(buffer+i2)=(long)pobj_c->GetStaticMembers().size();
379 i2+=sizeof(long);
380 BOOST_FOREACH( CMember *member, pobj_c->GetStaticMembers() ){
381 // 名前
382 lstrcpy(buffer+i2,member->GetName().c_str());
383 i2+=lstrlen(buffer+i2)+1;
384
385 // 型
386 *(long *)(buffer+i2)=member->GetType().GetBasicType();
387 i2+=sizeof(long);
388
389 // 型の拡張情報
390 SetLpIndex_DebugFile(buffer,&i2,member->GetType());
391
392 // アクセシビリティ
393 *(Prototype::Accessibility *)(buffer+i2)=member->GetAccessibility();
394 i2+=sizeof(Prototype::Accessibility);
395
396 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM);
397 i2+=sizeof(int)*MAX_ARRAYDIM;
398
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
439 Smoothie::Temp::pCompilingClass = NULL;
440
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);
460 IncludeFileInfo.ppFileNames=(char **)malloc(IncludeFileInfo.FilesNum*sizeof(char *));
461 for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
462 if(buffer[i2]=='\0') break;
463 IncludeFileInfo.ppFileNames[i3]=(char *)malloc(lstrlen(buffer+i2)+1);
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++;
474 source.SetBuffer( buffer + i2 );
475 i2+=lstrlen(buffer+i2)+1;
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
489 this->pobj_DBClass=new ClassesImpl();
490
491 int iMaxClassCount;
492 iMaxClassCount=*(long *)(buffer+i2);
493 i2+=sizeof(long);
494 for(i3=0;i3<iMaxClassCount;i3++){
495 //クラス名
496 // TODO: 名前空間が未完成
497 this->pobj_DBClass->Add(NamespaceScopes(),NamespaceScopesCollection(),buffer+i2,0);
498 i2+=lstrlen(buffer+i2)+1;
499 }
500
501 compiler.GetMeta().SetClasses( this->pobj_DBClass );
502
503
504 //////////////////
505 // TypeDef情報
506 //////////////////
507
508 //初期化
509 compiler.GetMeta().GetTypeDefs().clear();
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
518 // 名前空間に未対応
519 compiler.GetMeta().GetTypeDefs().push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2, -1 ) );
520
521 i2+=lstrlen(buffer+i2)+1;
522 }
523
524 //定数を取得
525 GetConstInfo();
526 extern CONSTINFO **ppConstHash;
527 this->ppConstHash=ppConstHash;
528
529
530 //グローバル変数情報
531 globalVars.clear();
532 int maxGlobalVars=*(long *)(buffer+i2);
533 i2+=sizeof(long);
534 for(i3=0;i3<maxGlobalVars;i3++){
535
536 //変数名
537 char *name = buffer+i2;
538 i2+=lstrlen(buffer+i2)+1;
539
540 int basicType = *(long *)(buffer+i2);
541 i2+=sizeof(long);
542
543 Type type( basicType );
544 GetLpIndex_DebugFile(buffer,&i2,type);
545
546 bool isRef = (buffer[i2++]) ? true:false;
547
548 bool isArray = (buffer[i2++]) ? true:false;
549
550 Variable *pVar = new VariableImpl( name, type, false, isRef );
551
552 if(isArray){
553 int SubScripts[MAX_ARRAYDIM];
554 for(i4=0;;i4++){
555 SubScripts[i4]=*(long *)(buffer+i2);
556 i2+=sizeof(long);
557
558 if(SubScripts[i4]==-1) break;
559 }
560
561 pVar->SetArray( SubScripts );
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);
575
576 //変数を追加
577 globalVars.push_back( pVar );
578 }
579
580 //グローバル実行領域のサイズ
581 GlobalOpBufferSize=*(long *)(buffer+i2);
582 i2+=sizeof(long);
583
584 //プロシージャ情報
585 GlobalProc *pUserProc;
586 SubNum=*(long *)(buffer+i2);
587 i2+=sizeof(long);
588 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
589 for(int i6=0;i6<SubNum;i6++){
590 char szParentClassName[VN_SIZE];
591 lstrcpy(szParentClassName,buffer+i2);
592 i2+=lstrlen(buffer+i2)+1;
593
594 const CClass *pClass = NULL;
595 if(szParentClassName[0]){
596 pClass=compiler.GetMeta().GetClasses().Find(szParentClassName);
597 }
598
599 //ID
600 int id=*(long *)(buffer+i2);
601 i2+=sizeof(long);
602
603 //名前
604 char *name = buffer+i2;
605 i2+=lstrlen(buffer+i2)+1;
606
607 // オブジェクトを生成
608 // TODO: 名前空間が未完成
609 pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false );
610 pUserProc->pNextData=0;
611 pUserProc->id=id;
612 pUserProc->SetParentClass( pClass );
613
614 pUserProc->beginOpAddress=*(long *)(buffer+i2);
615 i2+=sizeof(long);
616 pUserProc->endOpAddress=*(long *)(buffer+i2);
617 i2+=sizeof(long);
618
619 pUserProc->CompleteCompile();
620
621 //ローカル変数情報
622 pUserProc->localVars.clear();
623 int maxLocalVar=*(long *)(buffer+i2);
624 i2+=sizeof(long);
625 for(i3=0;i3<maxLocalVar;i3++){
626 //変数名
627 char *name = buffer+i2;
628 i2+=lstrlen(buffer+i2)+1;
629
630 int basicType = *(long *)(buffer+i2);
631 i2+=sizeof(long);
632
633 Type type( basicType );
634 GetLpIndex_DebugFile(buffer,&i2,type);
635
636 bool isRef = (buffer[i2++]) ? true:false;
637
638 bool isArray = (buffer[i2++]) ? true:false;
639
640 Variable *pVar = new VariableImpl( name, type, false, isRef );
641
642 if(isArray){
643 int SubScripts[MAX_ARRAYDIM];
644 for(i4=0;;i4++){
645 SubScripts[i4]=*(long *)(buffer+i2);
646 i2+=sizeof(long);
647
648 if(SubScripts[i4]==-1) break;
649 }
650
651 pVar->SetArray( SubScripts );
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
662 //メモリ位置
663 pVar->offset=*(long *)(buffer+i2);
664 i2+=sizeof(long);
665
666 //変数を追加
667 pUserProc->localVars.push_back( pVar );
668 }
669
670
671 /////////////////////////////////
672 // 格納位置を計算してpUserProcをセット
673 /////////////////////////////////
674
675 i4=hash_default(pUserProc->GetName().c_str());
676
677 GlobalProc *psi2;
678 if(ppSubHash[i4]){
679 psi2=ppSubHash[i4];
680 while(1){
681 if(psi2->pNextData==0){
682 psi2->pNextData=pUserProc;
683 break;
684 }
685 psi2=psi2->pNextData;
686 }
687 }
688 else{
689 ppSubHash[i4]=pUserProc;
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
701 pobj_c = const_cast<CClass *>( compiler.GetMeta().GetClasses().Find(szClassName) );
702
703 //仮想関数の数
704 pobj_c->SetVtblNum( *(long *)(buffer+i2) );
705 i2+=sizeof(long);
706
707 //アラインメント
708 pobj_c->iAlign=*(long *)(buffer+i2);
709 i2+=sizeof(long);
710
711 //静的メンバ
712 int nDynamicMember = *(long *)(buffer+i2);
713 i2+=sizeof(long);
714 for( i4=0; i4<nDynamicMember; i4++ ){
715 // 名前
716 string name = (char *)(buffer+i2);
717 i2+=lstrlen(buffer+i2)+1;
718
719 // 型
720 Type type( *(long *)(buffer+i2) );
721 i2+=sizeof(long);
722
723 // 型の拡張情報
724 GetLpIndex_DebugFile(buffer,&i2,type);
725
726 // アクセシビリティ
727 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
728 i2+=sizeof(Prototype::Accessibility);
729
730 CMember *member=new CMember( accessibility, name, type, false, "", "" );
731
732 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
733 i2+=sizeof(int)*MAX_ARRAYDIM;
734
735 pobj_c->GetDynamicMembers().push_back( member );
736 }
737
738 //メソッド
739 int nMethod = *(long *)(buffer+i2);
740 i2+=sizeof(long);
741 for( i4=0; i4<nMethod; i4++ ){
742
743 Prototype::Accessibility accessibility=*(Prototype::Accessibility *)(buffer+i2);
744 i2+=sizeof(Prototype::Accessibility);
745
746 char szInherits[VN_SIZE];
747 lstrcpy(szInherits,buffer+i2);
748 i2+=lstrlen(buffer+i2)+1;
749
750 const CClass *pobj_InheritsClass = NULL;
751 if(szInherits[0]){
752 pobj_InheritsClass=compiler.GetMeta().GetClasses().Find(szInherits);
753 }
754
755 lstrcpy(temp2,buffer+i2);
756 i2+=lstrlen(buffer+i2)+1;
757
758 const CClass *pobj_temp_c;
759 pobj_temp_c=pobj_InheritsClass;
760 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
761 i5=hash_default(temp2);
762 pUserProc=ppSubHash[i5];
763 while(1){
764 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
765 pUserProc=pUserProc->pNextData;
766 }
767
768 CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, 0,0,false, pobj_InheritsClass);
769
770 pobj_c->GetMethods().push_back( pMethod );
771 }
772
773 //静的メンバ
774 int nStaticMember = *(long *)(buffer+i2);
775 i2+=sizeof(long);
776 for( i4=0; i4<nStaticMember; i4++ ){
777 // 名前
778 string name = (char *)(buffer+i2);
779 i2+=lstrlen(buffer+i2)+1;
780
781 // 型
782 Type type( *(long *)(buffer+i2) );
783 i2+=sizeof(long);
784
785 // 型の拡張情報
786 GetLpIndex_DebugFile(buffer,&i2,type);
787
788 // アクセシビリティ
789 Prototype::Accessibility accessibility = *(Prototype::Accessibility *)(buffer+i2);
790 i2+=sizeof(Prototype::Accessibility);
791
792 CMember *member=new CMember( accessibility, name, type, false, "", "" );
793
794 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
795 i2+=sizeof(int)*MAX_ARRAYDIM;
796
797 pobj_c->GetStaticMembers().push_back( member );
798 }
799 }
800
801 HeapDefaultFree(buffer);
802 buffer=0;
803
804
805
806
807 extern GlobalProc **ppSubHash;
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;
833 SIZE_T accessBytes;
834 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
835 BreakStepCodeBuffer,
836 SizeOf_CodeSection,&accessBytes);
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;
850 SIZE_T accessBytes;
851 IMAGE_DOS_HEADER ImageDosHeader;
852 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&accessBytes);
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
862 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&accessBytes);
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),
870 &accessBytes);
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,
895 &accessBytes);
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
909 if(OpBuffer) free(OpBuffer);
910 OpBuffer=(char *)malloc(SizeOf_CodeSection);
911
912 ReadProcessMemory(hDebugProcess,
913 (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
914 SizeOf_CodeSection,&accessBytes);
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 //ソースコード
940 Smoothie::Lexical::source = source;
941
942 //コードと行番号の関係
943 extern int MaxLineInfoNum;
944 extern LINEINFO *pLineInfo;
945 MaxLineInfoNum=this->MaxLineInfoNum;
946 pLineInfo=this->pLineInfo;
947
948 // クラス情報
949 compiler.GetMeta().SetClasses( this->pobj_DBClass );
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;
962 extern GlobalProc **ppSubHash;
963 extern int SubNum;
964 ppSubHash=this->ppSubHash;
965 SubNum=this->SubNum;
966
967 extern UserProc *pSub_DebugSys_EndProc;
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++)
980 {
981 free(IncludeFileInfo.ppFileNames[i2]);
982 }
983 free(IncludeFileInfo.ppFileNames);
984
985 //クラスに関するメモリを解放
986 delete this->pobj_DBClass;
987 this->pobj_DBClass=0;
988
989 //サブルーチン情報のメモリ解放
990 DeleteSubInfo(ppSubHash,0,0);
991
992 //定数に関する情報を解放
993 DeleteConstInfo(ppConstHash);
994
995 //コードと行番号の関係を解放
996 HeapDefaultFree(pLineInfo);
997
998 //コードバッファを解放
999 free(OpBuffer);
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.