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

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