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

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

コード全体のリファクタリングを実施

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