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

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