source: dev/BasicCompiler_Common/DebugMiddleFile.cpp@ 14

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

LexicalAnalysisのベース部分を用意。

File size: 25.7 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
6#include "../BasicCompiler32/opcode.h"
7#endif
8
9#define MDLFILE_VER 0x70000003
10
11
12void SetLpIndex_DebugFile(char *buffer,int *p,int type,LONG_PTR lpIndex){
13 if(NATURAL_TYPE(type)==DEF_OBJECT){
14 lstrcpy(buffer+(*p),((CClass *)lpIndex)->name);
15 (*p)+=lstrlen(buffer+(*p))+1;
16 }
17 else{
18 *(LONG_PTR *)(buffer+(*p))=lpIndex;
19 (*p)+=sizeof(LONG_PTR);
20 }
21}
22
23
24void GetLpIndex_DebugFile(char *buffer,int *p,int type,LONG_PTR *plpIndex){
25 if(NATURAL_TYPE(type)==DEF_OBJECT){
26 char szClassName[VN_SIZE];
27 lstrcpy(szClassName,buffer+(*p));
28 (*p)+=lstrlen(buffer+(*p))+1;
29
30 *plpIndex=(LONG_PTR)pobj_DBClass->check(szClassName);
31 }
32 else{
33 *plpIndex=*(LONG_PTR *)(buffer+(*p));
34 (*p)+=sizeof(LONG_PTR);
35 }
36}
37
38
39
40CDebugSection::CDebugSection(){
41 memset(this,0,sizeof(CDebugSection));
42}
43CDebugSection::~CDebugSection(){
44 if(pobj_DBClass) DeleteDebugInfo();
45 if(buffer){
46 HeapDefaultFree(buffer);
47 buffer=0;
48 }
49}
50void CDebugSection::make(void){
51 extern VARIABLE *GlobalVar;
52 extern int MaxGlobalVarNum;
53 extern INCLUDEFILEINFO IncludeFileInfo;
54 int i2,i3,i4,i5,BufferSize;
55
56 if(buffer){
57 HeapDefaultFree(buffer);
58 buffer=0;
59 }
60
61 i2=0;
62
63 extern char *basbuf;
64 i3=lstrlen(basbuf);
65
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 extern CDBClass *pobj_DBClass;
122 pobj_DBClass->Iterator_Reset();
123
124 //個数
125 *(long *)(buffer+i2)=pobj_DBClass->Iterator_GetMaxCount();
126 i2+=sizeof(long);
127
128 while(pobj_DBClass->Iterator_HasNext()){
129 CClass *pobj_c;
130 pobj_c=pobj_DBClass->Iterator_GetNext();
131
132 //クラス名
133 lstrcpy(buffer+i2,pobj_c->name);
134 i2+=lstrlen(buffer+i2)+1;
135 }
136
137
138
139 //////////////////
140 // TypeDef情報
141 //////////////////
142
143 extern CDBTypeDef *pobj_DBTypeDef;
144 *(long *)(buffer+i2)=pobj_DBTypeDef->iNum;
145 i2+=sizeof(long);
146 for(i3=0;i3<pobj_DBTypeDef->iNum;i3++){
147 lstrcpy(buffer+i2,pobj_DBTypeDef->ppobj_TypeDef[i3]->lpszName);
148 i2+=lstrlen(buffer+i2)+1;
149
150 lstrcpy(buffer+i2,pobj_DBTypeDef->ppobj_TypeDef[i3]->lpszBaseName);
151 i2+=lstrlen(buffer+i2)+1;
152
153 //バッファが足りない場合は再確保
154 if(BufferSize<i2+32768){
155 BufferSize+=32768;
156 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
157 }
158 }
159
160
161 //グローバル変数情報
162 *(long *)(buffer+i2)=MaxGlobalVarNum;
163 i2+=sizeof(long);
164 for(i3=0;i3<MaxGlobalVarNum;i3++){
165 VARIABLE *pVar=&GlobalVar[i3];
166
167 //変数名
168 lstrcpy(buffer+i2,pVar->name);
169 i2+=lstrlen(buffer+i2)+1;
170
171 //型
172 *(long *)(buffer+i2)=pVar->type;
173 i2+=sizeof(long);
174
175 //型の拡張情報
176 SetLpIndex_DebugFile(buffer,&i2,pVar->type,pVar->u.index);
177
178 buffer[i2++]=(char)pVar->fRef;
179
180 buffer[i2++]=(char)pVar->bArray;
181
182 if(pVar->bArray){
183 for(i4=0;;i4++){
184 *(long *)(buffer+i2)=pVar->SubScripts[i4];
185 i2+=sizeof(long);
186 if(pVar->SubScripts[i4]==-1) break;
187 }
188 }
189
190 //レキシカルスコープ情報
191 *(long *)(buffer+i2)=pVar->ScopeStartAddress;
192 i2+=sizeof(long);
193 *(long *)(buffer+i2)=pVar->ScopeEndAddress;
194 i2+=sizeof(long);
195 *(long *)(buffer+i2)=pVar->ScopeLevel;
196 i2+=sizeof(long);
197
198 //メモリ位置
199 *(long *)(buffer+i2)=pVar->offset;
200 i2+=sizeof(long);
201
202 //バッファが足りない場合は再確保
203 if(BufferSize<i2+32768){
204 BufferSize+=32768;
205 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
206 }
207 }
208
209 //グローバル実行領域のサイズ
210 extern int GlobalOpBufferSize;
211 *(long *)(buffer+i2)=GlobalOpBufferSize;
212 i2+=sizeof(long);
213
214 //プロシージャ情報
215 extern SUBINFO **ppSubHash;
216 extern int SubNum;
217 SUBINFO *psi;
218 *(long *)(buffer+i2)=SubNum;
219 i2+=sizeof(long);
220 for(i3=0;i3<MAX_HASH;i3++){
221 psi=ppSubHash[i3];
222 while(psi){
223 if(psi->pobj_ParentClass){
224 lstrcpy(buffer+i2,psi->pobj_ParentClass->name);
225 i2+=lstrlen(buffer+i2)+1;
226 }
227 else{
228 lstrcpy(buffer+i2,"");
229 i2+=lstrlen(buffer+i2)+1;
230 }
231
232 //ID
233 *(long *)(buffer+i2)=psi->id;
234 i2+=sizeof(long);
235
236 //関数名
237 lstrcpy(buffer+i2,psi->name);
238 i2+=lstrlen(buffer+i2)+1;
239
240 *(long *)(buffer+i2)=psi->CompileAddress;
241 i2+=sizeof(long);
242 *(long *)(buffer+i2)=psi->EndOpAddr;
243 i2+=sizeof(long);
244
245 *(long *)(buffer+i2)=psi->bVirtual;
246 i2+=sizeof(long);
247
248 //ローカル変数情報
249 *(long *)(buffer+i2)=psi->VarNum;
250 i2+=sizeof(long);
251
252 //バッファが足りない場合は再確保
253 if(BufferSize<i2+32768){
254 BufferSize+=32768;
255 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
256 }
257
258 for(i4=0;i4<psi->VarNum;i4++){
259 VARIABLE *pVar=&psi->pVar[i4];
260 lstrcpy(buffer+i2,pVar->name);
261 i2+=lstrlen(buffer+i2)+1;
262
263 //型
264 *(long *)(buffer+i2)=pVar->type;
265 i2+=sizeof(long);
266
267 //型の拡張情報
268 SetLpIndex_DebugFile(buffer,&i2,pVar->type,pVar->u.index);
269
270 //参照型パラメータかどうか
271 buffer[i2++]=(char)pVar->fRef;
272
273 //配列かどうか
274 buffer[i2++]=(char)pVar->bArray;
275
276 //配列要素
277 if(pVar->bArray){
278 for(i5=0;;i5++){
279 *(long *)(buffer+i2)=pVar->SubScripts[i5];
280 i2+=sizeof(long);
281 if(pVar->SubScripts[i5]==-1) break;
282 }
283 }
284 else pVar->SubScripts[0]=-1;
285
286 //レキシカルスコープ情報
287 *(long *)(buffer+i2)=pVar->ScopeStartAddress;
288 i2+=sizeof(long);
289 *(long *)(buffer+i2)=pVar->ScopeEndAddress;
290 i2+=sizeof(long);
291 *(long *)(buffer+i2)=pVar->ScopeLevel;
292 i2+=sizeof(long);
293
294 //メモリ位置
295 *(long *)(buffer+i2)=pVar->offset;
296 i2+=sizeof(long);
297
298
299
300
301 //バッファが足りない場合は再確保
302 if(BufferSize<i2+32768){
303 BufferSize+=32768;
304 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
305 }
306 }
307
308 psi=psi->pNextData;
309 }
310 }
311
312
313
314 ///////////////////
315 // クラス情報
316 ///////////////////
317
318 //イテレータをリセット
319 pobj_DBClass->Iterator_Reset();
320
321 while(pobj_DBClass->Iterator_HasNext()){
322 CClass *pobj_c;
323 pobj_c=pobj_DBClass->Iterator_GetNext();
324
325
326 //クラス名
327 lstrcpy(buffer+i2,pobj_c->name);
328 i2+=lstrlen(buffer+i2)+1;
329
330 //仮想関数の数
331 *(long *)(buffer+i2)=pobj_c->vtbl_num;
332 i2+=sizeof(long);
333
334 //アラインメント
335 *(long *)(buffer+i2)=pobj_c->iAlign;
336 i2+=sizeof(long);
337
338 //メンバ
339 *(long *)(buffer+i2)=pobj_c->iMemberNum;
340 i2+=sizeof(long);
341 for(i4=0;i4<pobj_c->iMemberNum;i4++){
342 lstrcpy(buffer+i2,pobj_c->ppobj_Member[i4]->name);
343 i2+=lstrlen(buffer+i2)+1;
344
345 memcpy(buffer+i2,pobj_c->ppobj_Member[i4]->SubScripts,sizeof(int)*MAX_ARRAYDIM);
346 i2+=sizeof(int)*MAX_ARRAYDIM;
347
348 //型
349 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->TypeInfo.type;
350 i2+=sizeof(long);
351
352 //型の拡張情報
353 SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
354
355 *(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->dwAccess;
356 i2+=sizeof(long);
357
358 //バッファが足りない場合は再確保
359 if(BufferSize<i2+32768){
360 BufferSize+=32768;
361 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
362 }
363 }
364
365 //メソッド
366 *(long *)(buffer+i2)=pobj_c->iMethodNum;
367 i2+=sizeof(long);
368 for(i4=0;i4<pobj_c->iMethodNum;i4++){
369 *(long *)(buffer+i2)=pobj_c->ppobj_Method[i4]->dwAccess;
370 i2+=sizeof(long);
371 if(pobj_c->ppobj_Method[i4]->pobj_InheritsClass){
372 lstrcpy(buffer+i2,pobj_c->ppobj_Method[i4]->pobj_InheritsClass->name);
373 i2+=lstrlen(buffer+i2)+1;
374 }
375 else{
376 lstrcpy(buffer+i2,"");
377 i2+=lstrlen(buffer+i2)+1;
378 }
379 lstrcpy(buffer+i2,pobj_c->ppobj_Method[i4]->psi->name);
380 i2+=lstrlen(buffer+i2)+1;
381 }
382
383 //静的メンバ
384 *(long *)(buffer+i2)=pobj_c->iStaticMemberNum;
385 i2+=sizeof(long);
386 for(i4=0;i4<pobj_c->iStaticMemberNum;i4++){
387 lstrcpy(buffer+i2,pobj_c->ppobj_StaticMember[i4]->name);
388 i2+=lstrlen(buffer+i2)+1;
389
390 memcpy(buffer+i2,pobj_c->ppobj_StaticMember[i4]->SubScripts,sizeof(int)*MAX_ARRAYDIM);
391 i2+=sizeof(int)*MAX_ARRAYDIM;
392
393 //型
394 *(long *)(buffer+i2)=pobj_c->ppobj_StaticMember[i4]->TypeInfo.type;
395 i2+=sizeof(long);
396
397 //型の拡張情報
398 SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_StaticMember[i4]->TypeInfo.type,pobj_c->ppobj_StaticMember[i4]->TypeInfo.u.lpIndex);
399
400 *(long *)(buffer+i2)=pobj_c->ppobj_StaticMember[i4]->dwAccess;
401 i2+=sizeof(long);
402
403 //バッファが足りない場合は再確保
404 if(BufferSize<i2+32768){
405 BufferSize+=32768;
406 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
407 }
408 }
409
410 //バッファが足りない場合は再確保
411 if(BufferSize<i2+32768){
412 BufferSize+=32768;
413 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
414 }
415 }
416
417 length=i2;
418}
419
420char *CDebugSection::MakeSingleStepCode(void){
421 char *buffer;
422 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
423
424 memcpy(buffer,OpBuffer,SizeOf_CodeSection);
425
426 int i2;
427 for(i2=0;i2<MaxLineInfoNum;i2++){
428 if(!(
429 pLineInfo[i2].dwCodeType&CODETYPE_SYSTEMPROC||
430 pLineInfo[i2].dwCodeType&CODETYPE_DEBUGPROC
431 )){
432 //int 3
433 buffer[pLineInfo[i2].TopObp]=(char)0xCC;
434 }
435 }
436
437 return buffer;
438}
439BOOL CDebugSection::__load(void){
440 int i2,i3,i4,i5,num;
441 char temp2[MAX_PATH],*temp5;
442
443 i2=0;
444
445 //デバッグ用ファイルのバージョンをチェック
446 if(*(long *)(buffer+i2)<MDLFILE_VER){
447 HeapDefaultFree(buffer);
448 return 0;
449 }
450 i2+=sizeof(long);
451
452 //プラットフォームのビット数をチェック
453 if(*(long *)(buffer+i2)!=PLATFORM){
454 HeapDefaultFree(buffer);
455 return 0;
456 }
457 i2+=sizeof(long);
458
459 //インクルード情報
460 IncludeFileInfo.FilesNum=*(long *)(buffer+i2);
461 i2+=sizeof(long);
462 IncludeFileInfo.ppFileNames=(char **)HeapAlloc(hHeap,0,IncludeFileInfo.FilesNum*sizeof(char *));
463 for(i3=0;i3<IncludeFileInfo.FilesNum;i3++){
464 if(buffer[i2]=='\0') break;
465 IncludeFileInfo.ppFileNames[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
466 lstrcpy(IncludeFileInfo.ppFileNames[i3],buffer+i2);
467 i2+=lstrlen(buffer+i2)+1;
468 }
469 for(i2++,i3=0;;i2++,i3++){
470 IncludeFileInfo.LineOfFile[i3]=(long)buffer[i2];
471 if(IncludeFileInfo.LineOfFile[i3]==-1) break;
472 }
473
474 //ソースコード
475 i2++;
476 CSource::obj.SetSourceCode(buffer + i2);
477 this->basbuf=CSource::obj.SourceCode;
478 extern char *basbuf;
479 basbuf=this->basbuf;
480 i2+=lstrlen(buffer+i2)+1;
481
482 //コードと行番号の関係
483 MaxLineInfoNum=*(long *)(buffer+i2);
484 i2+=sizeof(long);
485 pLineInfo=(LINEINFO *)HeapAlloc(hHeap,0,MaxLineInfoNum*sizeof(LINEINFO)+1);
486 memcpy(pLineInfo,buffer+i2,MaxLineInfoNum*sizeof(LINEINFO));
487 i2+=MaxLineInfoNum*sizeof(LINEINFO);
488
489
490 ///////////////////////////////////////////
491 // クラス情報(名前のみ。詳細は後で取得)
492 ///////////////////////////////////////////
493
494 this->pobj_DBClass=new CDBClass();
495
496 int iMaxClassCount;
497 iMaxClassCount=*(long *)(buffer+i2);
498 i2+=sizeof(long);
499 for(i3=0;i3<iMaxClassCount;i3++){
500 //クラス名
501 pobj_DBClass->AddClass(buffer+i2,0);
502 i2+=lstrlen(buffer+i2)+1;
503 }
504
505 extern CDBClass *pobj_DBClass;
506 pobj_DBClass=this->pobj_DBClass;
507
508
509 //////////////////
510 // TypeDef情報
511 //////////////////
512
513 //初期化
514 pobj_DBTypeDef=new CDBTypeDef;
515
516 //個数を取得
517 num=*(long *)(buffer+i2);
518 i2+=sizeof(long);
519 for(i3=0;i3<num;i3++){
520 temp5=buffer+i2;
521 i2+=lstrlen(buffer+i2)+1;
522
523 pobj_DBTypeDef->add(temp5,buffer+i2);
524
525 i2+=lstrlen(buffer+i2)+1;
526 }
527
528 extern CDBTypeDef *pobj_DBTypeDef;
529 pobj_DBTypeDef=this->pobj_DBTypeDef;
530
531 //定数を取得
532 GetConstInfo();
533 extern CONSTINFO **ppConstHash;
534 this->ppConstHash=ppConstHash;
535
536
537 //グローバル変数情報
538 MaxGlobalVarNum=*(long *)(buffer+i2);
539 i2+=sizeof(long);
540 GlobalVar=(VARIABLE *)HeapAlloc(hHeap,0,MaxGlobalVarNum*sizeof(VARIABLE)+1);
541 for(i3=0;i3<MaxGlobalVarNum;i3++){
542 VARIABLE *pVar=&GlobalVar[i3];
543
544 //変数名
545 lstrcpy(pVar->name,buffer+i2);
546 i2+=lstrlen(buffer+i2)+1;
547
548 pVar->type=*(long *)(buffer+i2);
549 i2+=sizeof(long);
550
551 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
552
553 pVar->fRef=(long)buffer[i2++];
554
555 pVar->bArray=(long)buffer[i2++];
556 if(pVar->bArray){
557 for(i4=0;;i4++){
558 pVar->SubScripts[i4]=*(long *)(buffer+i2);
559 i2+=sizeof(long);
560
561 if(pVar->SubScripts[i4]==-1) break;
562 }
563 }
564
565 //レキシカルスコープ情報
566 pVar->ScopeStartAddress=*(long *)(buffer+i2);
567 i2+=sizeof(long);
568 pVar->ScopeEndAddress=*(long *)(buffer+i2);
569 i2+=sizeof(long);
570 pVar->ScopeLevel=*(long *)(buffer+i2);
571 i2+=sizeof(long);
572
573 //メモリ位置
574 pVar->offset=*(long *)(buffer+i2);
575 i2+=sizeof(long);
576 }
577
578 //グローバル実行領域のサイズ
579 GlobalOpBufferSize=*(long *)(buffer+i2);
580 i2+=sizeof(long);
581
582 //プロシージャ情報
583 SUBINFO *psi;
584 SubNum=*(long *)(buffer+i2);
585 i2+=sizeof(long);
586 ppSubHash=(SUBINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SUBINFO *));
587 for(i3=0;i3<SubNum;i3++){
588 psi=(SUBINFO *)HeapAlloc(hHeap,0,sizeof(SUBINFO));
589 psi->pNextData=0;
590
591 char szParentClassName[VN_SIZE];
592 lstrcpy(szParentClassName,buffer+i2);
593 i2+=lstrlen(buffer+i2)+1;
594
595 if(szParentClassName[0])
596 psi->pobj_ParentClass=pobj_DBClass->check(szParentClassName);
597 else psi->pobj_ParentClass=0;
598
599 //ID
600 psi->id=*(long *)(buffer+i2);
601 i2+=sizeof(long);
602
603 //名前
604 psi->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
605 lstrcpy(psi->name,buffer+i2);
606 i2+=lstrlen(buffer+i2)+1;
607
608 psi->CompileAddress=*(long *)(buffer+i2);
609 i2+=sizeof(long);
610 psi->EndOpAddr=*(long *)(buffer+i2);
611 i2+=sizeof(long);
612
613 psi->bVirtual=*(long *)(buffer+i2);
614 i2+=sizeof(long);
615
616 psi->ParmNum=0;
617 psi->pParmInfo=0;
618 psi->RealParmNum=0;
619 psi->pRealParmInfo=0;
620 psi->bCompile=1;
621
622 //ローカル変数情報
623 psi->VarNum=*(long *)(buffer+i2);
624 i2+=sizeof(long);
625 psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,psi->VarNum*sizeof(VARIABLE)+1);
626 for(i4=0;i4<psi->VarNum;i4++){
627 VARIABLE *pVar=&psi->pVar[i4];
628
629 //ローカル変数名
630 lstrcpy(pVar->name,buffer+i2);
631 i2+=lstrlen(buffer+i2)+1;
632
633 //型
634 pVar->type=*(long *)(buffer+i2);
635 i2+=sizeof(long);
636
637 //型の拡張情報
638 GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
639
640 //参照型パラメータかどうか
641 pVar->fRef=(long)buffer[i2++];
642
643 //配列かどうか
644 pVar->bArray=(long)buffer[i2++];
645 if(pVar->bArray){
646 for(i5=0;;i5++){
647 //配列要素
648 pVar->SubScripts[i5]=*(long *)(buffer+i2);
649 i2+=sizeof(long);
650
651 if(pVar->SubScripts[i5]==-1) break;
652 }
653 }
654
655 //レキシカルスコープ情報
656 pVar->ScopeStartAddress=*(long *)(buffer+i2);
657 i2+=sizeof(long);
658 pVar->ScopeEndAddress=*(long *)(buffer+i2);
659 i2+=sizeof(long);
660 pVar->ScopeLevel=*(long *)(buffer+i2);
661 i2+=sizeof(long);
662
663 //メモリ上の位置
664 pVar->offset=*(long *)(buffer+i2);
665 i2+=sizeof(long);
666 }
667
668
669 /////////////////////////////////
670 // 格納位置を計算してpsiをセット
671 /////////////////////////////////
672
673 i4=hash_default(psi->name);
674
675 SUBINFO *psi2;
676 if(ppSubHash[i4]){
677 psi2=ppSubHash[i4];
678 while(1){
679 if(psi2->pNextData==0){
680 psi2->pNextData=psi;
681 break;
682 }
683 psi2=psi2->pNextData;
684 }
685 }
686 else{
687 ppSubHash[i4]=psi;
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=pobj_DBClass->check(szClassName);
700
701 //仮想関数の数
702 pobj_c->vtbl_num=*(long *)(buffer+i2);
703 i2+=sizeof(long);
704
705 //アラインメント
706 pobj_c->iAlign=*(long *)(buffer+i2);
707 i2+=sizeof(long);
708
709 //メンバ
710 pobj_c->iMemberNum=*(long *)(buffer+i2);
711 i2+=sizeof(long);
712 pobj_c->ppobj_Member=
713 (CMember **)HeapAlloc(hHeap,0,pobj_c->iMemberNum*sizeof(CMember *));
714 for(i4=0;i4<pobj_c->iMemberNum;i4++){
715 pobj_c->ppobj_Member[i4]=new CMember();
716
717 pobj_c->ppobj_Member[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
718 lstrcpy(pobj_c->ppobj_Member[i4]->name,buffer+i2);
719 i2+=lstrlen(buffer+i2)+1;
720
721 memcpy(pobj_c->ppobj_Member[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
722 i2+=sizeof(int)*MAX_ARRAYDIM;
723
724 //型
725 pobj_c->ppobj_Member[i4]->TypeInfo.type=*(long *)(buffer+i2);
726 i2+=sizeof(long);
727
728 //型の拡張情報
729 GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,&pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
730
731 pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2);
732 i2+=sizeof(long);
733 }
734
735 //メソッド
736 pobj_c->iMethodNum=*(long *)(buffer+i2);
737 i2+=sizeof(long);
738 pobj_c->ppobj_Method=
739 (CMethod **)HeapAlloc(hHeap,0,pobj_c->iMethodNum*sizeof(CMethod *));
740 for(i4=0;i4<pobj_c->iMethodNum;i4++){
741 pobj_c->ppobj_Method[i4]=new CMethod();
742
743 pobj_c->ppobj_Method[i4]->dwAccess=*(long *)(buffer+i2);
744 i2+=sizeof(long);
745
746 char szInherits[VN_SIZE];
747 lstrcpy(szInherits,buffer+i2);
748 i2+=lstrlen(buffer+i2)+1;
749
750 if(szInherits[0])
751 pobj_c->ppobj_Method[i4]->pobj_InheritsClass=pobj_DBClass->check(szInherits);
752 else pobj_c->ppobj_Method[i4]->pobj_InheritsClass=0;
753
754 lstrcpy(temp2,buffer+i2);
755 i2+=lstrlen(buffer+i2)+1;
756
757 CClass *pobj_temp_c;
758 pobj_temp_c=pobj_c->ppobj_Method[i4]->pobj_InheritsClass;
759 if(pobj_temp_c==0) pobj_temp_c=pobj_c;
760 i5=hash_default(temp2);
761 psi=ppSubHash[i5];
762 while(1){
763 if(lstrcmp(psi->name,temp2)==0&&psi->pobj_ParentClass==pobj_temp_c) break;
764 psi=psi->pNextData;
765 }
766 pobj_c->ppobj_Method[i4]->psi=psi;
767 }
768
769 //静的メンバ
770 pobj_c->iStaticMemberNum=*(long *)(buffer+i2);
771 i2+=sizeof(long);
772 pobj_c->ppobj_StaticMember=
773 (CMember **)HeapAlloc(hHeap,0,pobj_c->iStaticMemberNum*sizeof(CMember *));
774 for(i4=0;i4<pobj_c->iStaticMemberNum;i4++){
775 pobj_c->ppobj_StaticMember[i4]=new CMember();
776
777 pobj_c->ppobj_StaticMember[i4]->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
778 lstrcpy(pobj_c->ppobj_StaticMember[i4]->name,buffer+i2);
779 i2+=lstrlen(buffer+i2)+1;
780
781 memcpy(pobj_c->ppobj_StaticMember[i4]->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM);
782 i2+=sizeof(int)*MAX_ARRAYDIM;
783
784 //型
785 pobj_c->ppobj_StaticMember[i4]->TypeInfo.type=*(long *)(buffer+i2);
786 i2+=sizeof(long);
787
788 //型の拡張情報
789 GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_StaticMember[i4]->TypeInfo.type,&pobj_c->ppobj_StaticMember[i4]->TypeInfo.u.lpIndex);
790
791 pobj_c->ppobj_StaticMember[i4]->dwAccess=*(long *)(buffer+i2);
792 i2+=sizeof(long);
793 }
794 }
795
796 HeapDefaultFree(buffer);
797 buffer=0;
798
799
800
801
802 extern SUBINFO **ppSubHash;
803 ppSubHash=this->ppSubHash;
804 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
805
806
807 SingleStepCodeBuffer=MakeSingleStepCode();
808
809
810 /////////////////////////////
811 // ブレークポイントを適用
812 /////////////////////////////
813
814 //インクルード情報
815 extern INCLUDEFILEINFO IncludeFileInfo;
816 IncludeFileInfo=this->IncludeFileInfo;
817
818 //コードと行番号の関係
819 extern int MaxLineInfoNum;
820 extern LINEINFO *pLineInfo;
821 MaxLineInfoNum=this->MaxLineInfoNum;
822 pLineInfo=this->pLineInfo;
823
824 BreakStepCodeBuffer=pobj_DBBreakPoint->update(OpBuffer,SizeOf_CodeSection);
825
826 //プロセスメモリにコピー
827 extern HANDLE hDebugProcess;
828 SIZE_T stAccBytes;
829 WriteProcessMemory(hDebugProcess,(void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),
830 BreakStepCodeBuffer,
831 SizeOf_CodeSection,&stAccBytes);
832
833
834 return 1;
835}
836
837BOOL CDebugSection::load(HMODULE hModule){
838 if(buffer){
839 HeapDefaultFree(buffer);
840 buffer=0;
841 }
842
843
844 extern HANDLE hDebugProcess;
845 SIZE_T stAccBytes;
846 IMAGE_DOS_HEADER ImageDosHeader;
847 ReadProcessMemory(hDebugProcess,hModule,&ImageDosHeader,sizeof(IMAGE_DOS_HEADER),&stAccBytes);
848
849 int pe_size;
850#ifdef _AMD64_
851 IMAGE_NT_HEADERS64 pe_hdr;
852 pe_size=sizeof(IMAGE_NT_HEADERS64);
853#else
854 IMAGE_NT_HEADERS pe_hdr;
855 pe_size=sizeof(IMAGE_NT_HEADERS);
856#endif
857 ReadProcessMemory(hDebugProcess,(void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew),&pe_hdr,pe_size,&stAccBytes);
858
859 IMAGE_SECTION_HEADER *pSectionHdr;
860 pSectionHdr=(IMAGE_SECTION_HEADER *)HeapAlloc(hHeap,0,pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER));
861 ReadProcessMemory(hDebugProcess,
862 (void *)(((ULONG_PTR)hModule)+ImageDosHeader.e_lfanew+pe_size),
863 pSectionHdr,
864 pe_hdr.FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
865 &stAccBytes);
866
867 int i;
868 for(i=0;i<pe_hdr.FileHeader.NumberOfSections;i++){
869
870 //リライタブルセクション内の情報
871 if(lstrcmp((char *)pSectionHdr[i].Name,".data")==0){
872 dwRVA_RWSection=pSectionHdr[i].VirtualAddress;
873 }
874
875 //コードセクション内の情報
876 if(lstrcmp((char *)pSectionHdr[i].Name,".text")==0){
877 dwRVA_CodeSection=pSectionHdr[i].VirtualAddress;
878 SizeOf_CodeSection=pSectionHdr[i].SizeOfRawData;
879 }
880
881 //デバッグセクション内の情報
882 if(lstrcmp((char *)pSectionHdr[i].Name,".debug")==0){
883 length=pSectionHdr[i].Misc.VirtualSize;
884 buffer=(char *)HeapAlloc(hHeap,0,length+1);
885
886 ReadProcessMemory(hDebugProcess,
887 (void *)(((ULONG_PTR)hModule)+pSectionHdr[i].VirtualAddress),
888 buffer,
889 length,
890 &stAccBytes);
891 buffer[length]=0;
892 }
893
894 }
895 HeapDefaultFree(pSectionHdr);
896
897 if(!buffer) return 0;
898
899
900 dwImageBase=(DWORD)(ULONG_PTR)hModule;
901
902
903
904 if(OpBuffer) HeapDefaultFree(OpBuffer);
905 OpBuffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
906
907 ReadProcessMemory(hDebugProcess,
908 (void *)(ULONG_PTR)(dwImageBase+dwRVA_CodeSection),OpBuffer,
909 SizeOf_CodeSection,&stAccBytes);
910
911
912 return __load();
913}
914
915void CDebugSection::choice(void){
916 //イメージベース
917 extern DWORD ImageBase;
918 ImageBase=this->dwImageBase;
919
920 //リライタブルセクションのRVA
921 extern int MemPos_RWSection;
922 MemPos_RWSection=this->dwRVA_RWSection;
923
924 //コードセクションのRVAとサイズ
925 extern int MemPos_CodeSection;
926 extern int FileSize_CodeSection;
927 MemPos_CodeSection=this->dwRVA_CodeSection;
928 FileSize_CodeSection=this->SizeOf_CodeSection;
929
930 //インクルード情報
931 extern INCLUDEFILEINFO IncludeFileInfo;
932 IncludeFileInfo=this->IncludeFileInfo;
933
934 //ソースコード
935 extern char *basbuf;
936 basbuf=this->basbuf;
937
938 //コードと行番号の関係
939 extern int MaxLineInfoNum;
940 extern LINEINFO *pLineInfo;
941 MaxLineInfoNum=this->MaxLineInfoNum;
942 pLineInfo=this->pLineInfo;
943
944 // クラス情報
945 extern CDBClass *pobj_DBClass;
946 pobj_DBClass=this->pobj_DBClass;
947
948 // TypeDef情報
949 extern CDBTypeDef *pobj_DBTypeDef;
950 pobj_DBTypeDef=this->pobj_DBTypeDef;
951
952 //定数を取得
953 extern CONSTINFO **ppConstHash;
954 ppConstHash=this->ppConstHash;
955
956 //グローバル変数に関する情報
957 extern VARIABLE *GlobalVar;
958 extern int MaxGlobalVarNum;
959 GlobalVar=this->GlobalVar;
960 MaxGlobalVarNum=this->MaxGlobalVarNum;
961
962 //グローバル実行領域のサイズ
963 extern int GlobalOpBufferSize;
964 GlobalOpBufferSize=this->GlobalOpBufferSize;
965
966 //プロシージャ
967 extern char **ppMacroNames;
968 ppMacroNames=0;
969 extern SUBINFO **ppSubHash;
970 extern int SubNum;
971 ppSubHash=this->ppSubHash;
972 SubNum=this->SubNum;
973
974 extern SUBINFO *pSub_DebugSys_EndProc;
975 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
976
977 //ネイティブコードバッファ
978 extern char *OpBuffer;
979 OpBuffer=this->OpBuffer;
980}
981
982void CDebugSection::DeleteDebugInfo(void){
983 int i2;
984
985 //インクルード情報を解放
986 for(i2=0;i2<IncludeFileInfo.FilesNum;i2++)
987 HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
988 HeapDefaultFree(IncludeFileInfo.ppFileNames);
989
990 //グローバル変数に関する情報を解放
991 HeapDefaultFree(GlobalVar);
992
993 //ローカル変数に関する情報を解放
994 SUBINFO *psi;
995 for(i2=0;i2<MAX_HASH;i2++){
996 psi=ppSubHash[i2];
997 while(psi){
998 if(psi->bCompile)
999 HeapDefaultFree(psi->pVar);
1000
1001 psi=psi->pNextData;
1002 }
1003 }
1004
1005 //クラスに関するメモリを解放
1006 delete pobj_DBClass;
1007 pobj_DBClass=0;
1008
1009 //サブルーチン情報のメモリ解放
1010 DeleteSubInfo(ppSubHash,0,0);
1011
1012 //定数に関する情報を解放
1013 DeleteConstInfo(ppConstHash);
1014
1015 //コードと行番号の関係を解放
1016 HeapDefaultFree(pLineInfo);
1017
1018 //コードバッファを解放
1019 HeapDefaultFree(OpBuffer);
1020 OpBuffer=0;
1021
1022 HeapDefaultFree(SingleStepCodeBuffer);
1023 SingleStepCodeBuffer=0;
1024
1025 HeapDefaultFree(BreakStepCodeBuffer);
1026 BreakStepCodeBuffer=0;
1027}
1028
1029
1030
1031CDBDebugSection::CDBDebugSection(){
1032 ppobj_ds=(CDebugSection **)HeapAlloc(hHeap,0,1);
1033 num=0;
1034}
1035CDBDebugSection::~CDBDebugSection(){
1036 int i;
1037 for(i=0;i<num;i++){
1038 delete ppobj_ds[i];
1039 }
1040 HeapDefaultFree(ppobj_ds);
1041}
1042
1043BOOL CDBDebugSection::add(HMODULE hModule){
1044 CDebugSection *pobj_d;
1045 pobj_d=new CDebugSection();
1046 if(!pobj_d->load(hModule)){
1047 //デバッグ情報が存在しないとき
1048 delete pobj_d;
1049 return 0;
1050 }
1051
1052 ppobj_ds=(CDebugSection **)HeapReAlloc(hHeap,0,ppobj_ds,(num+1)*sizeof(CDebugSection *));
1053 ppobj_ds[num]=pobj_d;
1054 num++;
1055
1056 return 1;
1057}
1058
1059void CDBDebugSection::del(HMODULE hModule){
1060 int i;
1061 for(i=0;i<num;i++){
1062 if((HMODULE)(ULONG_PTR)ppobj_ds[i]->dwImageBase==hModule){
1063 delete ppobj_ds[i];
1064
1065 num--;
1066 for(;i<num;i++){
1067 ppobj_ds[i]=ppobj_ds[i+1];
1068 }
1069 break;
1070 }
1071 }
1072}
1073
1074void CDBDebugSection::choice(int index){
1075 pobj_now=ppobj_ds[index];
1076 pobj_now->choice();
1077}
1078
1079
1080
1081CDBDebugSection *pobj_DBDebugSection;
Note: See TracBrowser for help on using the repository browser.